diff options
| author | Taylor Mullen <[email protected]> | 2025-04-18 17:47:49 -0400 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-04-18 17:51:16 -0400 |
| commit | e7fa39112a9b528bfe5a36a7b8b806de645eb977 (patch) | |
| tree | ec91ed950317d26b41674f08766bdb525bd5d43c /packages/cli/src/utils | |
| parent | dfae3f62848f0c8c175f0e992a479c3bf49e50ed (diff) | |
Manually fix hooks and utils linting errors (partial)
- More changes are to come, this is truly a partial change in order to not disrupt as many people as possible.
Part of https://b.corp.google.com/issues/411384603
Diffstat (limited to 'packages/cli/src/utils')
| -rw-r--r-- | packages/cli/src/utils/BackgroundTerminalAnalyzer.ts | 40 | ||||
| -rw-r--r-- | packages/cli/src/utils/getFolderStructure.ts | 11 |
2 files changed, 25 insertions, 26 deletions
diff --git a/packages/cli/src/utils/BackgroundTerminalAnalyzer.ts b/packages/cli/src/utils/BackgroundTerminalAnalyzer.ts index c73b1655..10448859 100644 --- a/packages/cli/src/utils/BackgroundTerminalAnalyzer.ts +++ b/packages/cli/src/utils/BackgroundTerminalAnalyzer.ts @@ -1,9 +1,10 @@ import { promises as fs } from 'fs'; -import { SchemaUnion, Type } from '@google/genai'; // Assuming these types exist +import { Content, SchemaUnion, Type } from '@google/genai'; // Assuming these types exist import { GeminiClient } from '../core/gemini-client.js'; // Assuming this path import { exec } from 'child_process'; // Needed for Windows process check import { promisify } from 'util'; // To promisify exec import { globalConfig } from '../config/config.js'; +import { getErrorMessage, isNodeError } from './errors.js'; // Promisify child_process.exec for easier async/await usage const execAsync = promisify(exec); @@ -11,8 +12,9 @@ const execAsync = promisify(exec); // Define the expected interface for the AI client dependency export interface AiClient { generateJson( - prompt: any[], // Keep flexible or define a stricter prompt structure type + prompt: Content[], // Keep flexible or define a stricter prompt structure type schema: SchemaUnion, + // eslint-disable-next-line @typescript-eslint/no-explicit-any ): Promise<any>; // Ideally, specify the expected JSON structure TAnalysisResult | TAnalysisFailure } @@ -98,20 +100,20 @@ export class BackgroundTerminalAnalyzer { // --- Robust File Reading --- try { currentStdout = await fs.readFile(tempStdoutFilePath, 'utf-8'); - } catch (error: any) { + } catch (error: unknown) { // If file doesn't exist yet or isn't readable, treat as empty, but log warning - if (error.code !== 'ENOENT') { + if (!isNodeError(error) || error.code !== 'ENOENT') { console.warn( - `Attempt ${attempts}: Failed to read stdout file ${tempStdoutFilePath}: ${error.message}`, + `Attempt ${attempts}: Failed to read stdout file ${tempStdoutFilePath}: ${getErrorMessage(error)}`, ); } } try { currentStderr = await fs.readFile(tempStderrFilePath, 'utf-8'); - } catch (error: any) { - if (error.code !== 'ENOENT') { + } catch (error: unknown) { + if (!isNodeError(error) || error.code !== 'ENOENT') { console.warn( - `Attempt ${attempts}: Failed to read stderr file ${tempStderrFilePath}: ${error.message}`, + `Attempt ${attempts}: Failed to read stderr file ${tempStderrFilePath}: ${getErrorMessage(error)}`, ); } } @@ -125,10 +127,10 @@ export class BackgroundTerminalAnalyzer { // Reread files one last time in case output was written just before exit try { currentStdout = await fs.readFile(tempStdoutFilePath, 'utf-8'); - } catch {} + } catch { /* ignore */ } try { currentStderr = await fs.readFile(tempStderrFilePath, 'utf-8'); - } catch {} + } catch { /* ignore */ } lastAnalysisResult = await this.analyzeOutputWithLLM( currentStdout, @@ -148,10 +150,10 @@ export class BackgroundTerminalAnalyzer { summary: `Process ended. Final analysis summary: ${lastAnalysisResult.summary}`, }; } - } catch (procCheckError: any) { + } catch (procCheckError: unknown) { // Log the error but allow polling to continue, as log analysis might still be useful console.warn( - `Could not check process status for PID ${pid} on attempt ${attempts}: ${procCheckError.message}`, + `Could not check process status for PID ${pid} on attempt ${attempts}: ${getErrorMessage(procCheckError)}`, ); // Decide if you want to bail out here or continue analysis based on logs only // For now, we continue. @@ -257,13 +259,13 @@ export class BackgroundTerminalAnalyzer { process.kill(pid, 0); return true; // If no error is thrown, process exists } - } catch (error: any) { - if (error.code === 'ESRCH') { + } catch (error: unknown) { + if (isNodeError(error) && error.code === 'ESRCH') { // ESRCH: Standard error code for "No such process" on Unix-like systems return false; } else if ( process.platform === 'win32' && - error.message.includes('No tasks are running') + getErrorMessage(error).includes('No tasks are running') ) { // tasklist specific error when PID doesn't exist return false; @@ -272,7 +274,7 @@ export class BackgroundTerminalAnalyzer { // Re-throwing might be appropriate depending on desired behavior. // Here, we log it and cautiously return true, assuming it *might* still be running. console.warn( - `isProcessRunning(${pid}) encountered error: ${error.message}. Assuming process might still exist.`, + `isProcessRunning(${pid}) encountered error: ${getErrorMessage(error)}. Assuming process might still exist.`, ); // Or you could throw the error: throw new Error(`Failed to check process status for PID ${pid}: ${error.message}`); return true; // Cautious assumption @@ -402,16 +404,14 @@ Based *only* on the provided stdout and stderr: } return response as AnalysisResult; // Cast after validation - } catch (error: any) { + } catch (error: unknown) { console.error( `LLM analysis call failed for command "${command}":`, error, ); // Ensure the error message passed back is helpful - const errorMessage = - error instanceof Error ? error.message : String(error); return { - error: `LLM analysis call encountered an error: ${errorMessage}`, + error: `LLM analysis call encountered an error: ${getErrorMessage(error)}`, inferredStatus: 'AnalysisFailed', }; } diff --git a/packages/cli/src/utils/getFolderStructure.ts b/packages/cli/src/utils/getFolderStructure.ts index d1e780a8..8192fc96 100644 --- a/packages/cli/src/utils/getFolderStructure.ts +++ b/packages/cli/src/utils/getFolderStructure.ts @@ -1,5 +1,6 @@ import * as fs from 'fs/promises'; import * as path from 'path'; +import { getErrorMessage, isNodeError } from './errors.js'; const MAX_ITEMS = 200; const TRUNCATION_INDICATOR = '...'; @@ -135,8 +136,8 @@ async function readFullStructure( folderInfo.files.length + folderInfo.subFolders.length + folderInfo.subFolders.reduce((sum, sf) => sum + sf.totalChildren, 0); - } catch (error: any) { - if (error.code === 'EACCES' || error.code === 'ENOENT') { + } catch (error: unknown) { + if (isNodeError(error) && (error.code === 'EACCES' || error.code === 'ENOENT')) { console.warn( `Warning: Could not read directory ${folderPath}: ${error.message}`, ); @@ -163,7 +164,6 @@ async function readFullStructure( function reduceStructure( fullInfo: FullFolderInfo, maxItems: number, - ignoredFolders: Set<string>, // Pass ignoredFolders for checking ): ReducedFolderNode { const rootReducedNode: ReducedFolderNode = { name: fullInfo.name, @@ -348,7 +348,6 @@ export async function getFolderStructure( const reducedRoot = reduceStructure( fullInfo, mergedOptions.maxItems, - mergedOptions.ignoredFolders, ); // 3. Count items in the *reduced* structure for the summary @@ -377,8 +376,8 @@ export async function getFolderStructure( `Showing ${reducedItemCount} of ${totalOriginalChildren} items (files + folders). ${disclaimer}`.trim(); return `${summary}\n\n${displayPath}/\n${structureLines.join('\n')}`; - } catch (error: any) { + } catch (error: unknown) { console.error(`Error getting folder structure for ${resolvedPath}:`, error); - return `Error processing directory "${resolvedPath}": ${error.message}`; + return `Error processing directory "${resolvedPath}": ${getErrorMessage(error)}`; } } |
