mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-05 02:40:55 -07:00
Adding session id as part of json o/p (#14504)
This commit is contained in:
@@ -29,18 +29,20 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
return `API Error: ${String(error)}`;
|
||||
}),
|
||||
JsonFormatter: vi.fn().mockImplementation(() => ({
|
||||
formatError: vi.fn((error: Error, code?: string | number) =>
|
||||
JSON.stringify(
|
||||
{
|
||||
error: {
|
||||
type: error.constructor.name,
|
||||
message: error.message,
|
||||
...(code && { code }),
|
||||
formatError: vi.fn(
|
||||
(error: Error, code?: string | number, sessionId?: string) =>
|
||||
JSON.stringify(
|
||||
{
|
||||
...(sessionId && { session_id: sessionId }),
|
||||
error: {
|
||||
type: error.constructor.name,
|
||||
message: error.message,
|
||||
...(code && { code }),
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
null,
|
||||
2,
|
||||
),
|
||||
),
|
||||
})),
|
||||
StreamJsonFormatter: vi.fn().mockImplementation(() => ({
|
||||
@@ -77,6 +79,8 @@ describe('errors', () => {
|
||||
let processExitSpy: MockInstance;
|
||||
let consoleErrorSpy: MockInstance;
|
||||
|
||||
const TEST_SESSION_ID = 'test-session-123';
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset mocks
|
||||
vi.clearAllMocks();
|
||||
@@ -93,6 +97,7 @@ describe('errors', () => {
|
||||
mockConfig = {
|
||||
getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
|
||||
getContentGeneratorConfig: vi.fn().mockReturnValue({ authType: 'test' }),
|
||||
getSessionId: vi.fn().mockReturnValue(TEST_SESSION_ID),
|
||||
} as unknown as Config;
|
||||
});
|
||||
|
||||
@@ -166,6 +171,7 @@ describe('errors', () => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
JSON.stringify(
|
||||
{
|
||||
session_id: TEST_SESSION_ID,
|
||||
error: {
|
||||
type: 'Error',
|
||||
message: 'Test error',
|
||||
@@ -188,6 +194,7 @@ describe('errors', () => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
JSON.stringify(
|
||||
{
|
||||
session_id: TEST_SESSION_ID,
|
||||
error: {
|
||||
type: 'Error',
|
||||
message: 'Test error',
|
||||
@@ -210,6 +217,7 @@ describe('errors', () => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
JSON.stringify(
|
||||
{
|
||||
session_id: TEST_SESSION_ID,
|
||||
error: {
|
||||
type: 'FatalInputError',
|
||||
message: 'Fatal error',
|
||||
@@ -246,6 +254,7 @@ describe('errors', () => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
JSON.stringify(
|
||||
{
|
||||
session_id: TEST_SESSION_ID,
|
||||
error: {
|
||||
type: 'Error',
|
||||
message: 'Error with status',
|
||||
@@ -398,6 +407,7 @@ describe('errors', () => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
JSON.stringify(
|
||||
{
|
||||
session_id: TEST_SESSION_ID,
|
||||
error: {
|
||||
type: 'FatalToolExecutionError',
|
||||
message: 'Error executing tool test-tool: Tool failed',
|
||||
@@ -467,6 +477,7 @@ describe('errors', () => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
JSON.stringify(
|
||||
{
|
||||
session_id: TEST_SESSION_ID,
|
||||
error: {
|
||||
type: 'FatalCancellationError',
|
||||
message: 'Operation cancelled.',
|
||||
@@ -529,6 +540,7 @@ describe('errors', () => {
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
JSON.stringify(
|
||||
{
|
||||
session_id: TEST_SESSION_ID,
|
||||
error: {
|
||||
type: 'FatalTurnLimitedError',
|
||||
message:
|
||||
|
||||
@@ -100,6 +100,7 @@ export function handleError(
|
||||
const formattedError = formatter.formatError(
|
||||
error instanceof Error ? error : new Error(getErrorMessage(error)),
|
||||
errorCode,
|
||||
config.getSessionId(),
|
||||
);
|
||||
|
||||
console.error(formattedError);
|
||||
@@ -152,6 +153,7 @@ export function handleToolError(
|
||||
const formattedError = formatter.formatError(
|
||||
toolExecutionError,
|
||||
errorType ?? toolExecutionError.exitCode,
|
||||
config.getSessionId(),
|
||||
);
|
||||
console.error(formattedError);
|
||||
} else {
|
||||
@@ -191,6 +193,7 @@ export function handleCancellationError(config: Config): never {
|
||||
const formattedError = formatter.formatError(
|
||||
cancellationError,
|
||||
cancellationError.exitCode,
|
||||
config.getSessionId(),
|
||||
);
|
||||
|
||||
console.error(formattedError);
|
||||
@@ -231,6 +234,7 @@ export function handleMaxTurnsExceededError(config: Config): never {
|
||||
const formattedError = formatter.formatError(
|
||||
maxTurnsError,
|
||||
maxTurnsError.exitCode,
|
||||
config.getSessionId(),
|
||||
);
|
||||
|
||||
console.error(formattedError);
|
||||
|
||||
Reference in New Issue
Block a user