The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { SystemError, SystemErrorTag } from "effect/PlatformError" |
| 2 | import * as PlatformError from "effect/PlatformError" |
| 3 | import type { PathLike } from "node:fs" |
| 4 | |
| 5 | /** @internal */ |
| 6 | export const handleErrnoException = (module: SystemError["module"], method: string) => |
| 7 | ( |
| 8 | err: NodeJS.ErrnoException, |
| 9 | [path]: [path: PathLike | number | string | ReadonlyArray<string>, ...args: Array<any>] |
| 10 | ): PlatformError.PlatformError => { |
| 11 | let reason: SystemErrorTag = "Unknown" |
| 12 | |
| 13 | switch (err.code) { |
| 14 | case "ENOENT": |
| 15 | reason = "NotFound" |
| 16 | break |
| 17 | |
| 18 | case "EACCES": |
| 19 | case "EPERM": |
| 20 | reason = "PermissionDenied" |
| 21 | break |
| 22 | |
| 23 | case "EEXIST": |
| 24 | reason = "AlreadyExists" |
| 25 | break |
| 26 | |
| 27 | case "EISDIR": |
| 28 | reason = "BadResource" |
| 29 | break |
| 30 | |
| 31 | case "ENOTDIR": |
| 32 | reason = "BadResource" |
| 33 | break |
| 34 | |
| 35 | case "EBUSY": |
| 36 | reason = "Busy" |
| 37 | break |
| 38 | |
| 39 | case "ELOOP": |
| 40 | reason = "BadResource" |
| 41 | break |
| 42 | } |
| 43 | |
| 44 | return PlatformError.systemError({ |
| 45 | _tag: reason, |
| 46 | module, |
| 47 | method, |
| 48 | pathOrDescriptor: path as string | number, |
| 49 | syscall: err.syscall, |
| 50 | cause: err |
| 51 | }) |
| 52 | } |