Skip to content

Commit b758006

Browse files
Masashi Hiranotargos
Masashi Hirano
authored andcommitted
fs: fix fsPromises.lchmod error on non-Mac
On non-macOS, fsPromises.lchmod throws AssertionError. Expected behavior is `Error [ERR_METHOD_NOT_IMPLEMENTED]`. `ERR_METHOD_NOT_IMPLEMENTED()` requires argument, but it wasn't set. Fixes `ERR_METHOD_NOT_IMPLEMENTED()` to `ERR_METHOD_NOT_IMPLEMENTED('lchmod()')`. PR-URL: #21435 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent 51db88b commit b758006

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/internal/fs/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ async function chmod(path, mode) {
371371

372372
async function lchmod(path, mode) {
373373
if (O_SYMLINK === undefined)
374-
throw new ERR_METHOD_NOT_IMPLEMENTED();
374+
throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()');
375375

376376
const fd = await open(path, O_WRONLY | O_SYMLINK);
377377
return fchmod(fd, mode).finally(fd.close.bind(fd));

test/parallel/test-fs-promises.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,26 @@ function verifyStatObject(stat) {
140140
(await realpath(newLink)).toLowerCase());
141141
assert.strictEqual(newPath.toLowerCase(),
142142
(await readlink(newLink)).toLowerCase());
143+
144+
const newMode = 0o666;
143145
if (common.isOSX) {
144146
// lchmod is only available on macOS
145-
const newMode = 0o666;
146147
await lchmod(newLink, newMode);
147148
stats = await lstat(newLink);
148149
assert.strictEqual(stats.mode & 0o777, newMode);
150+
} else {
151+
await Promise.all([
152+
assert.rejects(
153+
lchmod(newLink, newMode),
154+
common.expectsError({
155+
code: 'ERR_METHOD_NOT_IMPLEMENTED',
156+
type: Error,
157+
message: 'The lchmod() method is not implemented'
158+
})
159+
)
160+
]);
149161
}
150162

151-
152163
await unlink(newLink);
153164
}
154165

0 commit comments

Comments
 (0)