From 7116ab9c293f6b59ae8490b234dd99c72d5dd72b Mon Sep 17 00:00:00 2001 From: Brandon Keiji Date: Wed, 14 May 2025 00:12:04 +0000 Subject: fix: pass startup warnings to app as prop (#342) --- packages/cli/src/utils/startupWarnings.ts | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 packages/cli/src/utils/startupWarnings.ts (limited to 'packages/cli/src/utils') diff --git a/packages/cli/src/utils/startupWarnings.ts b/packages/cli/src/utils/startupWarnings.ts new file mode 100644 index 00000000..a55003e6 --- /dev/null +++ b/packages/cli/src/utils/startupWarnings.ts @@ -0,0 +1,40 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import fs from 'fs/promises'; +import os from 'os'; +import { join as pathJoin } from 'node:path'; +import { getErrorMessage } from '@gemini-code/server'; + +const warningsFilePath = pathJoin(os.tmpdir(), 'gemini-code-cli-warnings.txt'); + +export async function getStartupWarnings(): Promise { + try { + await fs.access(warningsFilePath); // Check if file exists + const warningsContent = await fs.readFile(warningsFilePath, 'utf-8'); + const warnings = warningsContent + .split('\n') + .filter((line) => line.trim() !== ''); + try { + await fs.unlink(warningsFilePath); + } catch { + warnings.push('Warning: Could not delete temporary warnings file.'); + } + return warnings; + } catch (err: unknown) { + // If fs.access throws, it means the file doesn't exist or is not accessible. + // This is not an error in the context of fetching warnings, so return empty. + // Only return an error message if it's not a "file not found" type error. + // However, the original logic returned an error message for any fs.existsSync failure. + // To maintain closer parity while making it async, we'll check the error code. + // ENOENT is "Error NO ENTry" (file not found). + if (err instanceof Error && 'code' in err && err.code === 'ENOENT') { + return []; // File not found, no warnings to return. + } + // For other errors (permissions, etc.), return the error message. + return [`Error checking/reading warnings file: ${getErrorMessage(err)}`]; + } +} -- cgit v1.2.3