* Reads the specified file gracefully. * @returns The file contents. Null if the file does not exist.
(filePath: string)
| 179 | * @returns The file contents. Null if the file does not exist. |
| 180 | */ |
| 181 | async function readFileGracefully(filePath: string): Promise<string | null> { |
| 182 | try { |
| 183 | return await fs.promises.readFile(filePath, 'utf8'); |
| 184 | } catch (error) { |
| 185 | if (isNodeJSWrappedError(error, Error) && error.code === 'ENOENT') { |
| 186 | return null; |
| 187 | } |
| 188 | throw error; |
| 189 | } |
| 190 | } |
no test coverage detected