* Get a human-readable error message from a filesystem error
(error: Error)
| 1015 | * Get a human-readable error message from a filesystem error |
| 1016 | */ |
| 1017 | function getFileSystemErrorMessage(error: Error): string { |
| 1018 | // Node.js filesystem errors have a 'code' property |
| 1019 | // eslint-disable-next-line no-restricted-syntax -- uses .path, not just .code |
| 1020 | const nodeError = error as NodeJS.ErrnoException |
| 1021 | if (nodeError.code) { |
| 1022 | switch (nodeError.code) { |
| 1023 | case 'ENOENT': |
| 1024 | return `Directory not found: ${nodeError.path ?? 'unknown path'}` |
| 1025 | case 'EACCES': |
| 1026 | return `Permission denied: ${nodeError.path ?? 'unknown path'}` |
| 1027 | case 'ENOSPC': |
| 1028 | return 'No space left on device' |
| 1029 | case 'EROFS': |
| 1030 | return 'Read-only file system' |
| 1031 | case 'EMFILE': |
| 1032 | return 'Too many open files' |
| 1033 | case 'EEXIST': |
| 1034 | return `File already exists: ${nodeError.path ?? 'unknown path'}` |
| 1035 | default: |
| 1036 | return `${nodeError.code}: ${nodeError.message}` |
| 1037 | } |
| 1038 | } |
| 1039 | return error.message |
| 1040 | } |
| 1041 |