mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-17 13:50:46 +01:00
333d9a4053
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
23 lines
826 B
TypeScript
23 lines
826 B
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
import * as fs from 'fs';
|
|
|
|
/**
|
|
* @returns file contents (utf8) or undefined if the file does not exist
|
|
*
|
|
* @throws if reading the file fails for any reason other than the file not existing
|
|
*/
|
|
export async function readFileIfExists(filePath: string): Promise<string | undefined> {
|
|
try {
|
|
const fileContents = await fs.promises.readFile(filePath, 'utf8');
|
|
return fileContents;
|
|
} catch (err) {
|
|
if (err.code === 'ENOENT') {
|
|
return undefined;
|
|
}
|
|
throw err;
|
|
}
|
|
}
|