summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Weidman <[email protected]>2025-08-13 17:57:11 +0000
committerGitHub <[email protected]>2025-08-13 17:57:11 +0000
commitb61a63aef4bcce9cb56fe46f10f0dc90b8fd6597 (patch)
tree278aa096f82fbad8f0b75cdfefdd108531ccc4a0
parent9c7fb870c1a7c80741fafdfc6837d4b92e373b2d (diff)
move errorParsing.ts to core (#6159)
-rw-r--r--packages/cli/src/nonInteractiveCli.ts2
-rw-r--r--packages/cli/src/ui/hooks/useGeminiStream.test.tsx7
-rw-r--r--packages/cli/src/ui/hooks/useGeminiStream.ts2
-rw-r--r--packages/core/src/index.ts1
-rw-r--r--packages/core/src/utils/errorParsing.test.ts (renamed from packages/cli/src/ui/utils/errorParsing.test.ts)11
-rw-r--r--packages/core/src/utils/errorParsing.ts (renamed from packages/cli/src/ui/utils/errorParsing.ts)12
-rw-r--r--packages/core/src/utils/quotaErrorDetection.ts7
7 files changed, 19 insertions, 23 deletions
diff --git a/packages/cli/src/nonInteractiveCli.ts b/packages/cli/src/nonInteractiveCli.ts
index c237e56b..f2efe8fc 100644
--- a/packages/cli/src/nonInteractiveCli.ts
+++ b/packages/cli/src/nonInteractiveCli.ts
@@ -13,10 +13,10 @@ import {
isTelemetrySdkInitialized,
GeminiEventType,
ToolErrorType,
+ parseAndFormatApiError,
} from '@google/gemini-cli-core';
import { Content, Part, FunctionCall } from '@google/genai';
-import { parseAndFormatApiError } from './ui/utils/errorParsing.js';
import { ConsolePatcher } from './ui/utils/ConsolePatcher.js';
export async function runNonInteractive(
diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx
index 37d63e9a..9eed0912 100644
--- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx
+++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx
@@ -51,6 +51,7 @@ const MockedGeminiClientClass = vi.hoisted(() =>
const MockedUserPromptEvent = vi.hoisted(() =>
vi.fn().mockImplementation(() => {}),
);
+const mockParseAndFormatApiError = vi.hoisted(() => vi.fn());
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
const actualCoreModule = (await importOriginal()) as any;
@@ -59,6 +60,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
GitService: vi.fn(),
GeminiClient: MockedGeminiClientClass,
UserPromptEvent: MockedUserPromptEvent,
+ parseAndFormatApiError: mockParseAndFormatApiError,
};
});
@@ -127,11 +129,6 @@ vi.mock('./slashCommandProcessor.js', () => ({
handleSlashCommand: vi.fn().mockReturnValue(false),
}));
-const mockParseAndFormatApiError = vi.hoisted(() => vi.fn());
-vi.mock('../utils/errorParsing.js', () => ({
- parseAndFormatApiError: mockParseAndFormatApiError,
-}));
-
// --- END MOCKS ---
describe('mergePartListUnions', () => {
diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts
index 6f3cb4fd..99b727b6 100644
--- a/packages/cli/src/ui/hooks/useGeminiStream.ts
+++ b/packages/cli/src/ui/hooks/useGeminiStream.ts
@@ -25,6 +25,7 @@ import {
UnauthorizedError,
UserPromptEvent,
DEFAULT_GEMINI_FLASH_MODEL,
+ parseAndFormatApiError,
} from '@google/gemini-cli-core';
import { type Part, type PartListUnion, FinishReason } from '@google/genai';
import {
@@ -37,7 +38,6 @@ import {
ToolCallStatus,
} from '../types.js';
import { isAtCommand } from '../utils/commandUtils.js';
-import { parseAndFormatApiError } from '../utils/errorParsing.js';
import { useShellCommandProcessor } from './shellCommandProcessor.js';
import { handleAtCommand } from './atCommandProcessor.js';
import { findLastSafeSplitPoint } from '../utils/markdownUtilities.js';
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 791446e3..a24cddbe 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -41,6 +41,7 @@ export * from './utils/systemEncoding.js';
export * from './utils/textUtils.js';
export * from './utils/formatters.js';
export * from './utils/filesearch/fileSearch.js';
+export * from './utils/errorParsing.js';
// Export services
export * from './services/fileDiscoveryService.js';
diff --git a/packages/cli/src/ui/utils/errorParsing.test.ts b/packages/core/src/utils/errorParsing.test.ts
index 770dffad..f2a4709a 100644
--- a/packages/cli/src/ui/utils/errorParsing.test.ts
+++ b/packages/core/src/utils/errorParsing.test.ts
@@ -6,12 +6,11 @@
import { describe, it, expect } from 'vitest';
import { parseAndFormatApiError } from './errorParsing.js';
-import {
- AuthType,
- UserTierId,
- DEFAULT_GEMINI_FLASH_MODEL,
- isProQuotaExceededError,
-} from '@google/gemini-cli-core';
+import { isProQuotaExceededError } from './quotaErrorDetection.js';
+import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
+import { UserTierId } from '../code_assist/types.js';
+import { AuthType } from '../core/contentGenerator.js';
+import { StructuredError } from '../core/turn.js';
describe('parseAndFormatApiError', () => {
const _enterpriseMessage =
diff --git a/packages/cli/src/ui/utils/errorParsing.ts b/packages/core/src/utils/errorParsing.ts
index 5031bc0a..aa15a652 100644
--- a/packages/cli/src/ui/utils/errorParsing.ts
+++ b/packages/core/src/utils/errorParsing.ts
@@ -5,15 +5,17 @@
*/
import {
- AuthType,
- UserTierId,
- DEFAULT_GEMINI_FLASH_MODEL,
- DEFAULT_GEMINI_MODEL,
isProQuotaExceededError,
isGenericQuotaExceededError,
isApiError,
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
const getRateLimitErrorMessageGoogleFree = (
diff --git a/packages/core/src/utils/quotaErrorDetection.ts b/packages/core/src/utils/quotaErrorDetection.ts
index 6fe9b312..1377b4fa 100644
--- a/packages/core/src/utils/quotaErrorDetection.ts
+++ b/packages/core/src/utils/quotaErrorDetection.ts
@@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import { StructuredError } from '../core/turn.js';
+
export interface ApiError {
error: {
code: number;
@@ -13,11 +15,6 @@ export interface ApiError {
};
}
-interface StructuredError {
- message: string;
- status?: number;
-}
-
export function isApiError(error: unknown): error is ApiError {
return (
typeof error === 'object' &&