mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 22:02:59 -07:00
feat(cli): handle invalid model names in useQuotaAndFallback (#19222)
This commit is contained in:
@@ -341,6 +341,46 @@ Your admin might have disabled the access. Contact them to enable the Preview Re
|
|||||||
|
|
||||||
expect(result.current.proQuotaRequest).toBeNull();
|
expect(result.current.proQuotaRequest).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle ModelNotFoundError with invalid model correctly', async () => {
|
||||||
|
const { result } = renderHook(() =>
|
||||||
|
useQuotaAndFallback({
|
||||||
|
config: mockConfig,
|
||||||
|
historyManager: mockHistoryManager,
|
||||||
|
userTier: UserTierId.FREE,
|
||||||
|
setModelSwitchedFromQuotaError: mockSetModelSwitchedFromQuotaError,
|
||||||
|
onShowAuthSelection: mockOnShowAuthSelection,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const handler = setFallbackHandlerSpy.mock
|
||||||
|
.calls[0][0] as FallbackModelHandler;
|
||||||
|
|
||||||
|
let promise: Promise<FallbackIntent | null>;
|
||||||
|
const error = new ModelNotFoundError('model not found', 404);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
promise = handler('invalid-model', 'gemini-2.5-pro', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = result.current.proQuotaRequest;
|
||||||
|
expect(request).not.toBeNull();
|
||||||
|
expect(request?.failedModel).toBe('invalid-model');
|
||||||
|
expect(request?.isModelNotFoundError).toBe(true);
|
||||||
|
|
||||||
|
const message = request!.message;
|
||||||
|
expect(message).toBe(
|
||||||
|
`Model "invalid-model" was not found or is invalid.
|
||||||
|
/model to switch models.`,
|
||||||
|
);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
result.current.handleProQuotaChoice('retry_always');
|
||||||
|
});
|
||||||
|
|
||||||
|
const intent = await promise!;
|
||||||
|
expect(intent).toBe('retry_always');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -83,16 +83,21 @@ export function useQuotaAndFallback({
|
|||||||
`/auth to switch to API key.`,
|
`/auth to switch to API key.`,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
message = messageLines.join('\n');
|
message = messageLines.join('\n');
|
||||||
} else if (
|
} else if (error instanceof ModelNotFoundError) {
|
||||||
error instanceof ModelNotFoundError &&
|
|
||||||
VALID_GEMINI_MODELS.has(failedModel)
|
|
||||||
) {
|
|
||||||
isModelNotFoundError = true;
|
isModelNotFoundError = true;
|
||||||
const messageLines = [
|
if (VALID_GEMINI_MODELS.has(failedModel)) {
|
||||||
`It seems like you don't have access to ${failedModel}.`,
|
const messageLines = [
|
||||||
`Your admin might have disabled the access. Contact them to enable the Preview Release Channel.`,
|
`It seems like you don't have access to ${failedModel}.`,
|
||||||
];
|
`Your admin might have disabled the access. Contact them to enable the Preview Release Channel.`,
|
||||||
message = messageLines.join('\n');
|
];
|
||||||
|
message = messageLines.join('\n');
|
||||||
|
} else {
|
||||||
|
const messageLines = [
|
||||||
|
`Model "${failedModel}" was not found or is invalid.`,
|
||||||
|
`/model to switch models.`,
|
||||||
|
];
|
||||||
|
message = messageLines.join('\n');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const messageLines = [
|
const messageLines = [
|
||||||
`We are currently experiencing high demand.`,
|
`We are currently experiencing high demand.`,
|
||||||
|
|||||||
Reference in New Issue
Block a user