mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 03:54:43 -07:00
migrate console.error to coreEvents/debugger for sandbox, logger, chatRecordingService (#12253)
This commit is contained in:
@@ -9,6 +9,7 @@ import { promises as fs } from 'node:fs';
|
||||
import type { Content } from '@google/genai';
|
||||
import type { Storage } from '../config/storage.js';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
import { coreEvents } from '../utils/events.js';
|
||||
|
||||
const LOG_FILE_NAME = 'logs.json';
|
||||
|
||||
@@ -158,7 +159,7 @@ export class Logger {
|
||||
: 0;
|
||||
this.initialized = true;
|
||||
} catch (err) {
|
||||
console.error('Failed to initialize logger:', err);
|
||||
coreEvents.emitFeedback('error', 'Failed to initialize logger:', err);
|
||||
this.initialized = false;
|
||||
}
|
||||
}
|
||||
@@ -315,7 +316,7 @@ export class Logger {
|
||||
|
||||
async saveCheckpoint(conversation: Content[], tag: string): Promise<void> {
|
||||
if (!this.initialized) {
|
||||
console.error(
|
||||
debugLogger.error(
|
||||
'Logger not initialized or checkpoint file path not set. Cannot save a checkpoint.',
|
||||
);
|
||||
return;
|
||||
@@ -325,13 +326,13 @@ export class Logger {
|
||||
try {
|
||||
await fs.writeFile(path, JSON.stringify(conversation, null, 2), 'utf-8');
|
||||
} catch (error) {
|
||||
console.error('Error writing to checkpoint file:', error);
|
||||
debugLogger.error('Error writing to checkpoint file:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async loadCheckpoint(tag: string): Promise<Content[]> {
|
||||
if (!this.initialized) {
|
||||
console.error(
|
||||
debugLogger.error(
|
||||
'Logger not initialized or checkpoint file path not set. Cannot load checkpoint.',
|
||||
);
|
||||
return [];
|
||||
@@ -354,14 +355,17 @@ export class Logger {
|
||||
// This is okay, it just means the checkpoint doesn't exist in either format.
|
||||
return [];
|
||||
}
|
||||
console.error(`Failed to read or parse checkpoint file ${path}:`, error);
|
||||
debugLogger.error(
|
||||
`Failed to read or parse checkpoint file ${path}:`,
|
||||
error,
|
||||
);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async deleteCheckpoint(tag: string): Promise<boolean> {
|
||||
if (!this.initialized || !this.geminiDir) {
|
||||
console.error(
|
||||
debugLogger.error(
|
||||
'Logger not initialized or checkpoint file path not set. Cannot delete checkpoint.',
|
||||
);
|
||||
return false;
|
||||
@@ -377,7 +381,10 @@ export class Logger {
|
||||
} catch (error) {
|
||||
const nodeError = error as NodeJS.ErrnoException;
|
||||
if (nodeError.code !== 'ENOENT') {
|
||||
console.error(`Failed to delete checkpoint file ${newPath}:`, error);
|
||||
debugLogger.error(
|
||||
`Failed to delete checkpoint file ${newPath}:`,
|
||||
error,
|
||||
);
|
||||
throw error; // Rethrow unexpected errors
|
||||
}
|
||||
// It's okay if it doesn't exist.
|
||||
@@ -392,7 +399,10 @@ export class Logger {
|
||||
} catch (error) {
|
||||
const nodeError = error as NodeJS.ErrnoException;
|
||||
if (nodeError.code !== 'ENOENT') {
|
||||
console.error(`Failed to delete checkpoint file ${oldPath}:`, error);
|
||||
debugLogger.error(
|
||||
`Failed to delete checkpoint file ${oldPath}:`,
|
||||
error,
|
||||
);
|
||||
throw error; // Rethrow unexpected errors
|
||||
}
|
||||
// It's okay if it doesn't exist.
|
||||
@@ -421,7 +431,7 @@ export class Logger {
|
||||
return false; // It truly doesn't exist in either format.
|
||||
}
|
||||
// A different error occurred.
|
||||
console.error(
|
||||
debugLogger.error(
|
||||
`Failed to check checkpoint existence for ${
|
||||
filePath ?? `path for tag "${tag}"`
|
||||
}:`,
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
PartListUnion,
|
||||
GenerateContentResponseUsageMetadata,
|
||||
} from '@google/genai';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
|
||||
export const SESSION_FILE_PREFIX = 'session-';
|
||||
|
||||
@@ -170,7 +171,7 @@ export class ChatRecordingService {
|
||||
this.queuedThoughts = [];
|
||||
this.queuedTokens = null;
|
||||
} catch (error) {
|
||||
console.error('Error initializing chat recording service:', error);
|
||||
debugLogger.error('Error initializing chat recording service:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +223,7 @@ export class ChatRecordingService {
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error saving message:', error);
|
||||
debugLogger.error('Error saving message to chat history.', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +240,7 @@ export class ChatRecordingService {
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error saving thought:', error);
|
||||
debugLogger.error('Error saving thought to chat history.', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +274,10 @@ export class ChatRecordingService {
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating message tokens:', error);
|
||||
debugLogger.error(
|
||||
'Error updating message tokens in chat history.',
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -367,7 +371,10 @@ export class ChatRecordingService {
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error adding tool call to message:', error);
|
||||
debugLogger.error(
|
||||
'Error adding tool call to message in chat history.',
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -381,7 +388,7 @@ export class ChatRecordingService {
|
||||
return JSON.parse(this.cachedLastConvData);
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
||||
console.error('Error reading conversation file:', error);
|
||||
debugLogger.error('Error reading conversation file.', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -413,7 +420,7 @@ export class ChatRecordingService {
|
||||
fs.writeFileSync(this.conversationFile, newContent);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error writing conversation file:', error);
|
||||
debugLogger.error('Error writing conversation file.', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -442,7 +449,7 @@ export class ChatRecordingService {
|
||||
const sessionPath = path.join(chatsDir, `${sessionId}.json`);
|
||||
fs.unlinkSync(sessionPath);
|
||||
} catch (error) {
|
||||
console.error('Error deleting session:', error);
|
||||
debugLogger.error('Error deleting session file.', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user