Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ function rm(path, options, callback) {
const h = vfsState.handlers;
if (h !== null && vfsVoid(h.rm(path, options), callback)) return;

callback = makeCallback(callback);
path = getValidatedPath(path);

validateRmOptions(path, options, false, (err, options) => {
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,29 @@ if (isGitPresent) {
});
}

// A missing callback is reported up front, the same way the other callback
// based fs APIs report it, rather than throwing from the removal itself once
// the work has already happened.
// Refs: https://github.com/nodejs/node/issues/65578
{
const dirname = tmpdir.resolve('rm-missing-callback');
fs.mkdirSync(dirname, { recursive: true });

for (const args of [
[dirname],
[dirname, { recursive: true }],
[dirname, { recursive: true }, 'not a function'],
]) {
assert.throws(() => fs.rm(...args), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
});
}

assert.ok(fs.existsSync(dirname), 'rm must not remove anything without a callback');
fs.rmSync(dirname, { recursive: true });
}

{
// IBMi has a different access permission mechanism
// This test should not be run as `root`
Expand Down
Loading