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

View File

@@ -590,7 +590,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
},
Date.now(),
);
console.error('Error refreshing memory:', error);
debugLogger.warn('Error refreshing memory:', error);
}
}, [config, historyManager, settings.merged]);

View File

@@ -15,6 +15,8 @@ import { type Config } from '../config/config.js';
import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/constants.js';
import { ToolErrorType } from './tool-error.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
export interface GlobPath {
@@ -238,9 +240,8 @@ class GlobToolInvocation extends BaseToolInvocation<
returnDisplay: `Found ${fileCount} matching file(s)`,
};
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : String(error);
console.error(`GlobLogic execute Error: ${errorMessage}`, error);
debugLogger.warn(`GlobLogic execute Error`, error);
const errorMessage = getErrorMessage(error);
const rawError = `Error during glob search operation: ${errorMessage}`;
return {
llmContent: rawError,

View File

@@ -199,7 +199,7 @@ class GrepToolInvocation extends BaseToolInvocation<
returnDisplay: `Found ${matchCount} ${matchTerm}`,
};
} catch (error) {
console.error(`Error during GrepLogic execution: ${error}`);
debugLogger.warn(`Error during GrepLogic execution: ${error}`);
const errorMessage = getErrorMessage(error);
return {
llmContent: `Error during grep search operation: ${errorMessage}`,
@@ -552,7 +552,7 @@ class GrepToolInvocation extends BaseToolInvocation<
return allMatches;
} catch (error: unknown) {
console.error(
debugLogger.warn(
`GrepLogic: Error in performGrepSearch (Strategy: ${strategyUsed}): ${getErrorMessage(
error,
)}`,

View File

@@ -248,11 +248,6 @@ describe('LSTool', () => {
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 result = await invocation.execute(abortSignal);
@@ -261,13 +256,7 @@ describe('LSTool', () => {
expect(result.llmContent).not.toContain('problematic.txt');
expect(result.returnDisplay).toBe('Listed 1 item(s).');
// Verify error was logged
expect(consoleErrorSpy).toHaveBeenCalledWith(
expect.stringMatching(/Error accessing.*problematic\.txt/s),
);
statSpy.mockRestore();
consoleErrorSpy.mockRestore();
});
});

View File

@@ -14,6 +14,7 @@ import type { Config } from '../config/config.js';
import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/constants.js';
import { ToolErrorType } from './tool-error.js';
import { LS_TOOL_NAME } from './tool-names.js';
import { debugLogger } from '../utils/debugLogger.js';
/**
* Parameters for the LS tool
@@ -205,7 +206,7 @@ class LSToolInvocation extends BaseToolInvocation<LSToolParams, ToolResult> {
});
} catch (error) {
// Log error internally but don't fail the whole listing
console.error(`Error accessing ${fullPath}: ${error}`);
debugLogger.debug(`Error accessing ${fullPath}: ${error}`);
}
}