move errorParsing.ts to core (#6159)
This commit is contained in:
parent
9c7fb870c1
commit
b61a63aef4
|
@ -13,10 +13,10 @@ import {
|
||||||
isTelemetrySdkInitialized,
|
isTelemetrySdkInitialized,
|
||||||
GeminiEventType,
|
GeminiEventType,
|
||||||
ToolErrorType,
|
ToolErrorType,
|
||||||
|
parseAndFormatApiError,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import { Content, Part, FunctionCall } from '@google/genai';
|
import { Content, Part, FunctionCall } from '@google/genai';
|
||||||
|
|
||||||
import { parseAndFormatApiError } from './ui/utils/errorParsing.js';
|
|
||||||
import { ConsolePatcher } from './ui/utils/ConsolePatcher.js';
|
import { ConsolePatcher } from './ui/utils/ConsolePatcher.js';
|
||||||
|
|
||||||
export async function runNonInteractive(
|
export async function runNonInteractive(
|
||||||
|
|
|
@ -51,6 +51,7 @@ const MockedGeminiClientClass = vi.hoisted(() =>
|
||||||
const MockedUserPromptEvent = vi.hoisted(() =>
|
const MockedUserPromptEvent = vi.hoisted(() =>
|
||||||
vi.fn().mockImplementation(() => {}),
|
vi.fn().mockImplementation(() => {}),
|
||||||
);
|
);
|
||||||
|
const mockParseAndFormatApiError = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||||
const actualCoreModule = (await importOriginal()) as any;
|
const actualCoreModule = (await importOriginal()) as any;
|
||||||
|
@ -59,6 +60,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||||
GitService: vi.fn(),
|
GitService: vi.fn(),
|
||||||
GeminiClient: MockedGeminiClientClass,
|
GeminiClient: MockedGeminiClientClass,
|
||||||
UserPromptEvent: MockedUserPromptEvent,
|
UserPromptEvent: MockedUserPromptEvent,
|
||||||
|
parseAndFormatApiError: mockParseAndFormatApiError,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -127,11 +129,6 @@ vi.mock('./slashCommandProcessor.js', () => ({
|
||||||
handleSlashCommand: vi.fn().mockReturnValue(false),
|
handleSlashCommand: vi.fn().mockReturnValue(false),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const mockParseAndFormatApiError = vi.hoisted(() => vi.fn());
|
|
||||||
vi.mock('../utils/errorParsing.js', () => ({
|
|
||||||
parseAndFormatApiError: mockParseAndFormatApiError,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// --- END MOCKS ---
|
// --- END MOCKS ---
|
||||||
|
|
||||||
describe('mergePartListUnions', () => {
|
describe('mergePartListUnions', () => {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import {
|
||||||
UnauthorizedError,
|
UnauthorizedError,
|
||||||
UserPromptEvent,
|
UserPromptEvent,
|
||||||
DEFAULT_GEMINI_FLASH_MODEL,
|
DEFAULT_GEMINI_FLASH_MODEL,
|
||||||
|
parseAndFormatApiError,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import { type Part, type PartListUnion, FinishReason } from '@google/genai';
|
import { type Part, type PartListUnion, FinishReason } from '@google/genai';
|
||||||
import {
|
import {
|
||||||
|
@ -37,7 +38,6 @@ import {
|
||||||
ToolCallStatus,
|
ToolCallStatus,
|
||||||
} from '../types.js';
|
} from '../types.js';
|
||||||
import { isAtCommand } from '../utils/commandUtils.js';
|
import { isAtCommand } from '../utils/commandUtils.js';
|
||||||
import { parseAndFormatApiError } from '../utils/errorParsing.js';
|
|
||||||
import { useShellCommandProcessor } from './shellCommandProcessor.js';
|
import { useShellCommandProcessor } from './shellCommandProcessor.js';
|
||||||
import { handleAtCommand } from './atCommandProcessor.js';
|
import { handleAtCommand } from './atCommandProcessor.js';
|
||||||
import { findLastSafeSplitPoint } from '../utils/markdownUtilities.js';
|
import { findLastSafeSplitPoint } from '../utils/markdownUtilities.js';
|
||||||
|
|
|
@ -41,6 +41,7 @@ export * from './utils/systemEncoding.js';
|
||||||
export * from './utils/textUtils.js';
|
export * from './utils/textUtils.js';
|
||||||
export * from './utils/formatters.js';
|
export * from './utils/formatters.js';
|
||||||
export * from './utils/filesearch/fileSearch.js';
|
export * from './utils/filesearch/fileSearch.js';
|
||||||
|
export * from './utils/errorParsing.js';
|
||||||
|
|
||||||
// Export services
|
// Export services
|
||||||
export * from './services/fileDiscoveryService.js';
|
export * from './services/fileDiscoveryService.js';
|
||||||
|
|
|
@ -6,12 +6,11 @@
|
||||||
|
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { parseAndFormatApiError } from './errorParsing.js';
|
import { parseAndFormatApiError } from './errorParsing.js';
|
||||||
import {
|
import { isProQuotaExceededError } from './quotaErrorDetection.js';
|
||||||
AuthType,
|
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
||||||
UserTierId,
|
import { UserTierId } from '../code_assist/types.js';
|
||||||
DEFAULT_GEMINI_FLASH_MODEL,
|
import { AuthType } from '../core/contentGenerator.js';
|
||||||
isProQuotaExceededError,
|
import { StructuredError } from '../core/turn.js';
|
||||||
} from '@google/gemini-cli-core';
|
|
||||||
|
|
||||||
describe('parseAndFormatApiError', () => {
|
describe('parseAndFormatApiError', () => {
|
||||||
const _enterpriseMessage =
|
const _enterpriseMessage =
|
|
@ -5,15 +5,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AuthType,
|
|
||||||
UserTierId,
|
|
||||||
DEFAULT_GEMINI_FLASH_MODEL,
|
|
||||||
DEFAULT_GEMINI_MODEL,
|
|
||||||
isProQuotaExceededError,
|
isProQuotaExceededError,
|
||||||
isGenericQuotaExceededError,
|
isGenericQuotaExceededError,
|
||||||
isApiError,
|
isApiError,
|
||||||
isStructuredError,
|
isStructuredError,
|
||||||
} from '@google/gemini-cli-core';
|
} from './quotaErrorDetection.js';
|
||||||
|
import {
|
||||||
|
DEFAULT_GEMINI_MODEL,
|
||||||
|
DEFAULT_GEMINI_FLASH_MODEL,
|
||||||
|
} from '../config/models.js';
|
||||||
|
import { UserTierId } from '../code_assist/types.js';
|
||||||
|
import { AuthType } from '../core/contentGenerator.js';
|
||||||
|
|
||||||
// Free Tier message functions
|
// Free Tier message functions
|
||||||
const getRateLimitErrorMessageGoogleFree = (
|
const getRateLimitErrorMessageGoogleFree = (
|
|
@ -4,6 +4,8 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { StructuredError } from '../core/turn.js';
|
||||||
|
|
||||||
export interface ApiError {
|
export interface ApiError {
|
||||||
error: {
|
error: {
|
||||||
code: number;
|
code: number;
|
||||||
|
@ -13,11 +15,6 @@ export interface ApiError {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StructuredError {
|
|
||||||
message: string;
|
|
||||||
status?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isApiError(error: unknown): error is ApiError {
|
export function isApiError(error: unknown): error is ApiError {
|
||||||
return (
|
return (
|
||||||
typeof error === 'object' &&
|
typeof error === 'object' &&
|
||||||
|
|
Loading…
Reference in New Issue