* Get a human-readable error message from a filesystem error
(error: Error)
| 1041 | * Get a human-readable error message from a filesystem error |
| 1042 | */ |
| 1043 | function getFileSystemErrorMessage(error: Error): string { |
| 1044 | // Node.js filesystem errors have a 'code' property |
| 1045 | // eslint-disable-next-line no-restricted-syntax -- uses .path, not just .code |
| 1046 | const nodeError = error as NodeJS.ErrnoException |
| 1047 | if (nodeError.code) { |
| 1048 | switch (nodeError.code) { |
| 1049 | case 'ENOENT': |
| 1050 | return `Directory not found: ${nodeError.path ?? 'unknown path'}` |
| 1051 | case 'EACCES': |
| 1052 | return `Permission denied: ${nodeError.path ?? 'unknown path'}` |
| 1053 | case 'ENOSPC': |
| 1054 | return 'No space left on device' |
| 1055 | case 'EROFS': |
| 1056 | return 'Read-only file system' |
| 1057 | case 'EMFILE': |
| 1058 | return 'Too many open files' |
| 1059 | case 'EEXIST': |
| 1060 | return `File already exists: ${nodeError.path ?? 'unknown path'}` |
| 1061 | default: |
| 1062 | return `${nodeError.code}: ${nodeError.message}` |
| 1063 | } |
| 1064 | } |
| 1065 | return error.message |
| 1066 | } |