use debugLogger instead of console (#12095)

This commit is contained in:
Tommaso Sciortino
2025-10-27 11:35:16 -07:00
committed by GitHub
parent e115083fac
commit 0e4dce23b2
5 changed files with 9 additions and 18 deletions
+1 -1
View File
@@ -590,7 +590,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
}, },
Date.now(), Date.now(),
); );
console.error('Error refreshing memory:', error); debugLogger.warn('Error refreshing memory:', error);
} }
}, [config, historyManager, settings.merged]); }, [config, historyManager, settings.merged]);
+4 -3
View File
@@ -15,6 +15,8 @@ import { type Config } from '../config/config.js';
import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/constants.js'; import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/constants.js';
import { ToolErrorType } from './tool-error.js'; import { ToolErrorType } from './tool-error.js';
import { GLOB_TOOL_NAME } from './tool-names.js'; import { GLOB_TOOL_NAME } from './tool-names.js';
import { getErrorMessage } from '../utils/errors.js';
import { debugLogger } from '../utils/debugLogger.js';
// Subset of 'Path' interface provided by 'glob' that we can implement for testing // Subset of 'Path' interface provided by 'glob' that we can implement for testing
export interface GlobPath { export interface GlobPath {
@@ -238,9 +240,8 @@ class GlobToolInvocation extends BaseToolInvocation<
returnDisplay: `Found ${fileCount} matching file(s)`, returnDisplay: `Found ${fileCount} matching file(s)`,
}; };
} catch (error) { } catch (error) {
const errorMessage = debugLogger.warn(`GlobLogic execute Error`, error);
error instanceof Error ? error.message : String(error); const errorMessage = getErrorMessage(error);
console.error(`GlobLogic execute Error: ${errorMessage}`, error);
const rawError = `Error during glob search operation: ${errorMessage}`; const rawError = `Error during glob search operation: ${errorMessage}`;
return { return {
llmContent: rawError, llmContent: rawError,
+2 -2
View File
@@ -199,7 +199,7 @@ class GrepToolInvocation extends BaseToolInvocation<
returnDisplay: `Found ${matchCount} ${matchTerm}`, returnDisplay: `Found ${matchCount} ${matchTerm}`,
}; };
} catch (error) { } catch (error) {
console.error(`Error during GrepLogic execution: ${error}`); debugLogger.warn(`Error during GrepLogic execution: ${error}`);
const errorMessage = getErrorMessage(error); const errorMessage = getErrorMessage(error);
return { return {
llmContent: `Error during grep search operation: ${errorMessage}`, llmContent: `Error during grep search operation: ${errorMessage}`,
@@ -552,7 +552,7 @@ class GrepToolInvocation extends BaseToolInvocation<
return allMatches; return allMatches;
} catch (error: unknown) { } catch (error: unknown) {
console.error( debugLogger.warn(
`GrepLogic: Error in performGrepSearch (Strategy: ${strategyUsed}): ${getErrorMessage( `GrepLogic: Error in performGrepSearch (Strategy: ${strategyUsed}): ${getErrorMessage(
error, error,
)}`, )}`,
-11
View File
@@ -248,11 +248,6 @@ describe('LSTool', () => {
return originalStat(p); return originalStat(p);
}); });
// Spy on console.error to verify it's called
const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => {});
const invocation = lsTool.build({ path: tempRootDir }); const invocation = lsTool.build({ path: tempRootDir });
const result = await invocation.execute(abortSignal); const result = await invocation.execute(abortSignal);
@@ -261,13 +256,7 @@ describe('LSTool', () => {
expect(result.llmContent).not.toContain('problematic.txt'); expect(result.llmContent).not.toContain('problematic.txt');
expect(result.returnDisplay).toBe('Listed 1 item(s).'); expect(result.returnDisplay).toBe('Listed 1 item(s).');
// Verify error was logged
expect(consoleErrorSpy).toHaveBeenCalledWith(
expect.stringMatching(/Error accessing.*problematic\.txt/s),
);
statSpy.mockRestore(); statSpy.mockRestore();
consoleErrorSpy.mockRestore();
}); });
}); });
+2 -1
View File
@@ -14,6 +14,7 @@ import type { Config } from '../config/config.js';
import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/constants.js'; import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/constants.js';
import { ToolErrorType } from './tool-error.js'; import { ToolErrorType } from './tool-error.js';
import { LS_TOOL_NAME } from './tool-names.js'; import { LS_TOOL_NAME } from './tool-names.js';
import { debugLogger } from '../utils/debugLogger.js';
/** /**
* Parameters for the LS tool * Parameters for the LS tool
@@ -205,7 +206,7 @@ class LSToolInvocation extends BaseToolInvocation<LSToolParams, ToolResult> {
}); });
} catch (error) { } catch (error) {
// Log error internally but don't fail the whole listing // Log error internally but don't fail the whole listing
console.error(`Error accessing ${fullPath}: ${error}`); debugLogger.debug(`Error accessing ${fullPath}: ${error}`);
} }
} }