Path: blob/main/extensions/copilot/test/base/fileUtils.ts
13389 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import * as fs from 'fs';56/**7* @returns file contents (utf8) or undefined if the file does not exist8*9* @throws if reading the file fails for any reason other than the file not existing10*/11export async function readFileIfExists(filePath: string): Promise<string | undefined> {12try {13const fileContents = await fs.promises.readFile(filePath, 'utf8');14return fileContents;15} catch (err) {16if (err.code === 'ENOENT') {17return undefined;18}19throw err;20}21}222324