Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use InvalidStateError class
  • Loading branch information
RaisinTen committed Jun 5, 2021
commit 8c76097a2a4aec5271a241672ab51469e71b712f
23 changes: 11 additions & 12 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ function removeAsync(dir) {
// IBMi has a different access permission mechanism
// This test should not be run as `root`
if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) {
class InvalidStateError extends Error {
constructor(err) {
super('Invalid state');
this.cause = err;
}
}

// Check that deleting a file that cannot be accessed using rmsync throws:
// https://github.com/nodejs/node/issues/38683
{
Expand Down Expand Up @@ -319,9 +326,7 @@ function removeAsync(dir) {
try { fs.chmodSync(filePath, 0o777); } catch {}

if (!isValidState(fs.existsSync(filePath), err)) {
const e = new Error('Invalid state');
e.cause = err;
throw e;
throw new InvalidStateError(err);
}
}

Expand All @@ -340,9 +345,7 @@ function removeAsync(dir) {
try { fs.chmodSync(filePath, 0o777); } catch {}

if (!isValidState(fs.existsSync(filePath), err)) {
const e = new Error('Invalid state');
e.cause = err;
throw e;
throw new InvalidStateError(err);
}
}));
}
Expand Down Expand Up @@ -384,9 +387,7 @@ function removeAsync(dir) {
try { fs.chmodSync(leaf, 0o777); } catch {}

if (!isValidState(fs.existsSync(root), err)) {
const e = new Error('Invalid state');
e.cause = err;
throw e;
throw new InvalidStateError(err);
}
}

Expand All @@ -408,9 +409,7 @@ function removeAsync(dir) {
try { fs.chmodSync(leaf, 0o777); } catch {}

if (!isValidState(fs.existsSync(root), err)) {
const e = new Error('Invalid state');
e.cause = err;
throw e;
throw new InvalidStateError(err);
}
}));
}
Expand Down