Merge commit '36c66dd290d3ce6eb1ccd310d0c658d4a32bb8eb' as 'repos/effect'
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import type { SystemError, SystemErrorTag } from "effect/PlatformError"
|
||||
import * as PlatformError from "effect/PlatformError"
|
||||
import type { PathLike } from "node:fs"
|
||||
|
||||
/** @internal */
|
||||
export const handleErrnoException = (module: SystemError["module"], method: string) =>
|
||||
(
|
||||
err: NodeJS.ErrnoException,
|
||||
[path]: [path: PathLike | number | string | readonly string[], ...args: Array<any>]
|
||||
): PlatformError.PlatformError => {
|
||||
let reason: SystemErrorTag = "Unknown"
|
||||
|
||||
switch (err.code) {
|
||||
case "ENOENT":
|
||||
reason = "NotFound"
|
||||
break
|
||||
|
||||
case "EACCES":
|
||||
reason = "PermissionDenied"
|
||||
break
|
||||
|
||||
case "EEXIST":
|
||||
reason = "AlreadyExists"
|
||||
break
|
||||
|
||||
case "EISDIR":
|
||||
reason = "BadResource"
|
||||
break
|
||||
|
||||
case "ENOTDIR":
|
||||
reason = "BadResource"
|
||||
break
|
||||
|
||||
case "EBUSY":
|
||||
reason = "Busy"
|
||||
break
|
||||
|
||||
case "ELOOP":
|
||||
reason = "BadResource"
|
||||
break
|
||||
}
|
||||
|
||||
return PlatformError.systemError({
|
||||
_tag: reason,
|
||||
module,
|
||||
method,
|
||||
pathOrDescriptor: path as string | number,
|
||||
syscall: err.syscall,
|
||||
cause: err
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user