Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import type {PlatformError, SystemErrorReason} from '@effect/platform/Error'
import {SystemError} from '@effect/platform/Error'
import {Cause} from 'effect'
import type {PathLike} from 'node:fs'
/**
* @internal
*/
export const handleErrnoException =
(module: SystemError['module'], method: string) =>
(
err: NodeJS.ErrnoException,
[path]: [path: PathLike | number, ...args: Array<NodeJS.ErrnoException>],
): PlatformError => {
let reason: SystemErrorReason = 'Unknown'
switch (err.code) {
case 'ENOENT': {
reason = 'NotFound'
break
}
/* v8 ignore next 29 */
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 new SystemError({
reason,
module,
method,
pathOrDescriptor: path as string | number,
syscall: err.syscall,
cause: Cause.fail(err.message),
})
}
|