extract console error to util func (#11675)

This commit is contained in:
Abhi
2025-10-22 16:09:10 -04:00
committed by GitHub
parent a7faa2080f
commit b40f67b76a
9 changed files with 19 additions and 63 deletions
+4 -3
View File
@@ -10,6 +10,7 @@ import { homedir } from 'node:os';
import type { MCPServerConfig } from '@google/gemini-cli-core';
import {
debugLogger,
GEMINI_DIR,
getErrorMessage,
type TelemetrySettings,
@@ -97,10 +98,10 @@ export function loadSettings(workspaceDir: string): Settings {
}
if (settingsErrors.length > 0) {
console.error('Errors loading settings:');
debugLogger.error('Errors loading settings:');
for (const error of settingsErrors) {
console.error(` Path: ${error.path}`);
console.error(` Message: ${error.message}`);
debugLogger.error(` Path: ${error.path}`);
debugLogger.error(` Message: ${error.message}`);
}
}
@@ -224,37 +224,11 @@ const TOOLS_SHELL_FAKE_SCHEMA: SettingsSchemaType = {
},
} as unknown as SettingsSchemaType;
// Helper function to simulate key presses (commented out for now)
// const simulateKeyPress = async (keyData: Partial<Key> & { name: string }) => {
// if (currentKeypressHandler) {
// const key: Key = {
// ctrl: false,
// meta: false,
// shift: false,
// paste: false,
// sequence: keyData.sequence || keyData.name,
// ...keyData,
// };
// currentKeypressHandler(key);
// // Allow React to process the state update
// await new Promise(resolve => setTimeout(resolve, 10));
// }
// };
// Mock console.log to avoid noise in tests
// const originalConsoleLog = console.log;
// const originalConsoleError = console.error;
describe('SettingsDialog', () => {
// Simple delay function for remaining tests that need gradual migration
const wait = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms));
beforeEach(() => {
// Reset keypress mock state (variables are commented out)
// currentKeypressHandler = null;
// isKeypressActive = false;
// console.log = vi.fn();
// console.error = vi.fn();
mockToggleVimEnabled.mockResolvedValue(true);
});
@@ -262,11 +236,6 @@ describe('SettingsDialog', () => {
TEST_ONLY.clearFlattenedSchema();
vi.clearAllMocks();
vi.resetAllMocks();
// Reset keypress mock state (variables are commented out)
// currentKeypressHandler = null;
// isKeypressActive = false;
// console.log = originalConsoleLog;
// console.error = originalConsoleError;
});
describe('Initial Rendering', () => {
+2 -1
View File
@@ -21,6 +21,7 @@ import {
MINIMUM_MAX_HEIGHT,
} from '../components/shared/MaxSizedBox.js';
import type { LoadedSettings } from '../../config/settings.js';
import { debugLogger } from '@google/gemini-cli-core';
// Configure theming and parsing utilities.
const lowlight = createLowlight(common);
@@ -191,7 +192,7 @@ export function colorizeCode(
</MaxSizedBox>
);
} catch (error) {
console.error(
debugLogger.warn(
`[colorizeCode] Error highlighting code for language "${language}":`,
error,
);
@@ -158,7 +158,7 @@ class GeminiAgent {
);
isAuthenticated = true;
} catch (e) {
console.error(`Authentication failed: ${e}`);
debugLogger.error(`Authentication failed: ${e}`);
}
}
@@ -660,7 +660,7 @@ class Session {
);
}
} catch (globError) {
console.error(
debugLogger.error(
`Error during glob search for ${pathName}: ${getErrorMessage(globError)}`,
);
}
@@ -670,7 +670,7 @@ class Session {
);
}
} else {
console.error(
debugLogger.error(
`Error stating path ${pathName}. Path ${pathName} will be skipped.`,
);
}
+6 -17
View File
@@ -1199,24 +1199,13 @@ export class Config {
!allowedTools || allowedTools.includes(definition.name);
if (isAllowed && !isExcluded) {
try {
const messageBusEnabled = this.getEnableMessageBusIntegration();
const wrapper = new SubagentToolWrapper(
definition,
this,
messageBusEnabled ? this.getMessageBus() : undefined,
);
registry.registerTool(wrapper);
} catch (error) {
console.error(
`Failed to wrap agent '${definition.name}' as a tool:`,
error,
);
}
} else if (this.getDebugMode()) {
debugLogger.log(
`[Config] Skipping registration of agent '${definition.name}' due to allow/exclude configuration.`,
const messageBusEnabled = this.getEnableMessageBusIntegration();
const wrapper = new SubagentToolWrapper(
definition,
this,
messageBusEnabled ? this.getMessageBus() : undefined,
);
registry.registerTool(wrapper);
}
}
}
+1 -2
View File
@@ -1502,9 +1502,8 @@ ${JSON.stringify(
break;
}
}
} catch (error) {
} catch (_) {
// If the test framework times out, that also demonstrates the infinite loop
console.error('Test timed out or errored:', error);
}
// Assert that the fix works - the loop should stop at MAX_TURNS
+1 -1
View File
@@ -267,7 +267,7 @@ class MemoryToolInvocation extends BaseToolInvocation<
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : String(error);
console.error(
console.warn(
`[MemoryTool] Error executing save_memory for fact "${fact}": ${errorMessage}`,
);
return {
@@ -107,10 +107,6 @@ describe('summarizers', () => {
expect(mockGeminiClient.generateContent).toHaveBeenCalledTimes(1);
expect(result).toBe(longText);
expect(console.error).toHaveBeenCalledWith(
'Failed to summarize tool output.',
error,
);
});
it('should construct the correct prompt for summarization', async () => {
+2 -1
View File
@@ -13,6 +13,7 @@ import type {
import type { GeminiClient } from '../core/client.js';
import { DEFAULT_GEMINI_FLASH_LITE_MODEL } from '../config/models.js';
import { getResponseText, partToString } from './partUtils.js';
import { debugLogger } from './debugLogger.js';
/**
* A function that summarizes the result of a tool execution.
@@ -90,7 +91,7 @@ export async function summarizeToolOutput(
)) as unknown as GenerateContentResponse;
return getResponseText(parsedResponse) || textToSummarize;
} catch (error) {
console.error('Failed to summarize tool output.', error);
debugLogger.warn('Failed to summarize tool output.', error);
return textToSummarize;
}
}