Skip to content

Commit 28a9ff8

Browse files
committed
process: improve process.cwd() error message
1 parent 55600e6 commit 28a9ff8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/node_process_methods.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ static void Cwd(const FunctionCallbackInfo<Value>& args) {
163163
size_t cwd_len = sizeof(buf);
164164
int err = uv_cwd(buf, &cwd_len);
165165
if (err) {
166-
return env->ThrowUVException(err, "uv_cwd");
166+
std::string msg = std::string("process.cwd failed with error ") + uv_strerror(err);
167+
return env->ThrowUVException(err, "uv_cwd", msg.c_str());
167168
}
168-
169169
Local<String> cwd;
170170
if (String::NewFromUtf8(env->isolate(), buf, NewStringType::kNormal, cwd_len)
171171
.ToLocal(&cwd)) {

test/known_issues/test-cwd-enoent-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (process.argv[2] === 'child') {
2323
process.chdir(dir);
2424
fs.rmdirSync(dir);
2525
assert.throws(process.cwd,
26-
/^Error: ENOENT: no such file or directory, uv_cwd$/);
26+
/^Error: ENOENT: process\.cwd failed with error no such file or directory, uv_cwd$/);
2727

2828
const r = cp.spawnSync(process.execPath, [__filename, 'child']);
2929

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { isMainThread } = require('worker_threads');
5+
const assert = require('assert');
6+
const fs = require('fs');
7+
8+
if (!isMainThread) {
9+
common.skip('process.chdir is not available in Workers');
10+
}
11+
12+
// Fails with EINVAL on SmartOS, EBUSY on Windows, EBUSY on AIX.
13+
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi) {
14+
common.skip('cannot rmdir current working directory');
15+
}
16+
17+
const tmpdir = require('../common/tmpdir');
18+
const dirname = `${tmpdir.path}/cwd-does-not-exist-${process.pid}`;
19+
20+
tmpdir.refresh();
21+
fs.mkdirSync(dirname);
22+
process.chdir(dirname);
23+
fs.rmdirSync(dirname);
24+
25+
assert.throws(
26+
() => process.cwd(),
27+
{
28+
code: 'ENOENT',
29+
message: 'ENOENT: process.cwd failed with error no such file or directory, uv_cwd',
30+
}
31+
);

0 commit comments

Comments
 (0)