forked from isaacs/rimraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eperm stuff make sure other test still run guard against eperm during windows readdir
- Loading branch information
1 parent
d7b3cd4
commit 784cd09
Showing
11 changed files
with
432 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
import { errorCode } from './error.js' | ||
|
||
export const ignoreENOENT = async <T>(p: Promise<T>, rethrow?: unknown) => | ||
const pickError = (er: unknown, er2?: unknown) => { | ||
if (!er2) { | ||
return er | ||
} | ||
if (er2 instanceof Error) { | ||
er2.cause = er | ||
} | ||
return er2 | ||
} | ||
|
||
export const ignoreENOENT = async <T>(p: Promise<T>, er2?: unknown) => | ||
p.catch(er => { | ||
if (errorCode(er) === 'ENOENT') { | ||
return | ||
} | ||
throw rethrow ?? er | ||
throw pickError(er, er2) | ||
}) | ||
|
||
export const ignoreENOENTSync = <T>(fn: () => T, rethrow?: unknown) => { | ||
export const ignoreENOENTSync = <T>(fn: () => T, er2?: unknown) => { | ||
try { | ||
return fn() | ||
} catch (er) { | ||
if (errorCode(er) === 'ENOENT') { | ||
return | ||
} | ||
throw rethrow ?? er | ||
throw pickError(er, er2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.