CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
startupWarnings.ts41 linesDownload Raw Back to utils
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7import fs from 'node:fs/promises';8import os from 'node:os';9import { join as pathJoin } from 'node:path';10import { getErrorMessage } from '@qwen-code/qwen-code-core';11 12const warningsFilePath = pathJoin(os.tmpdir(), 'qwen-code-warnings.txt');13 14export async function getStartupWarnings(): Promise<string[]> {15  try {16    await fs.access(warningsFilePath); // Check if file exists17    const warningsContent = await fs.readFile(warningsFilePath, 'utf-8');18    const warnings = warningsContent19      .split('\n')20      .filter((line) => line.trim() !== '');21    try {22      await fs.unlink(warningsFilePath);23    } catch {24      warnings.push('Warning: Could not delete temporary warnings file.');25    }26    return warnings;27  } catch (err: unknown) {28    // If fs.access throws, it means the file doesn't exist or is not accessible.29    // This is not an error in the context of fetching warnings, so return empty.30    // Only return an error message if it's not a "file not found" type error.31    // However, the original logic returned an error message for any fs.existsSync failure.32    // To maintain closer parity while making it async, we'll check the error code.33    // ENOENT is "Error NO ENTry" (file not found).34    if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {35      return []; // File not found, no warnings to return.36    }37    // For other errors (permissions, etc.), return the error message.38    return [`Error checking/reading warnings file: ${getErrorMessage(err)}`];39  }40}41 
basant307/AI_Governance_Project · CoolFace