| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,9 +163,17 @@ static void Cwd(const FunctionCallbackInfo<Value>& args) { | |||
| 163 | 163 | size_t cwd_len = sizeof(buf); | |
| 164 | 164 | int err = uv_cwd(buf, &cwd_len); | |
| 165 | 165 | if (err) { | |
| 166 | - return env->ThrowUVException(err, "uv_cwd"); | ||
| 166 | + std::string err_msg = | ||
| 167 | + std::string("process.cwd failed with error ") + uv_strerror(err); | ||
| 168 | + if (err == UV_ENOENT) { | ||
| 169 | + // If err == UV_ENOENT it is necessary to notice the user | ||
| 170 | + // that the current working dir was likely removed. | ||
| 171 | + err_msg = err_msg + | ||
| 172 | + ", the current working directory was likely removed " + | ||
| 173 | + "without changing the working directory"; | ||
| 174 | + } | ||
| 175 | + return env->ThrowUVException(err, "uv_cwd", err_msg.c_str()); | ||
| 167 | 176 | } | |
| 168 | - | ||
| 169 | 177 | Local<String> cwd; | |
| 170 | 178 | if (String::NewFromUtf8(env->isolate(), buf, NewStringType::kNormal, cwd_len) | |
| 171 | 179 | .ToLocal(&cwd)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ if (process.argv[2] === 'child') { | |||
| 23 | 23 | process.chdir(dir); | |
| 24 | 24 | fs.rmdirSync(dir); | |
| 25 | 25 | 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, the current working directory was likely removed without changing the working directory, uv_cwd$/); | ||
| 27 | 27 | ||
| 28 | 28 | const r = cp.spawnSync(process.execPath, [__filename, 'child']); | |
| 29 | 29 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 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,' + | ||
| 30 | + ' the current working directory was likely removed without changing the working directory, uv_cwd', | ||
| 31 | + } | ||
| 32 | + ); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments