(path: string)
| 878 | } |
| 879 | |
| 880 | function readCodeFile(path: string): string { |
| 881 | try { |
| 882 | return readFileSync(resolveAbsolute(path), 'utf8'); |
| 883 | } catch (err) { |
| 884 | const code = (err as NodeJS.ErrnoException).code; |
| 885 | if (code === 'ENOENT') { |
| 886 | throw localValidationError('code-file', `file does not exist: ${path}`); |
| 887 | } |
| 888 | if (code === 'EACCES') { |
| 889 | throw localValidationError('code-file', `permission denied reading ${path}`); |
| 890 | } |
| 891 | const reason = err instanceof Error ? err.message : 'unknown error'; |
| 892 | throw localValidationError('code-file', `cannot read ${path}: ${reason}`); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | function resolveAbsolute(path: string): string { |
| 897 | return isAbsolute(path) ? path : resolve(process.cwd(), path); |
no test coverage detected