mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 13:22:35 -07:00
fix(core): remove unsafe type assertion suppressions in error utils (#19881)
Co-authored-by: David Pierce <davidapierce@google.com>
This commit is contained in:
@@ -280,16 +280,9 @@ function parseResponseData(error: GaxiosError): ResponseData | undefined {
|
||||
export function isAuthenticationError(error: unknown): boolean {
|
||||
// Check for MCP SDK errors with code property
|
||||
// (SseError and StreamableHTTPError both have numeric 'code' property)
|
||||
if (
|
||||
error &&
|
||||
typeof error === 'object' &&
|
||||
'code' in error &&
|
||||
typeof (error as { code: unknown }).code === 'number'
|
||||
) {
|
||||
// Safe access after check
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const errorCode = (error as { code: number }).code;
|
||||
if (errorCode === 401) {
|
||||
if (error && typeof error === 'object' && 'code' in error) {
|
||||
const errorCode: unknown = (error as Record<string, unknown>)['code'];
|
||||
if (typeof errorCode === 'number' && errorCode === 401) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,23 +16,33 @@ export interface ApiError {
|
||||
}
|
||||
|
||||
export function isApiError(error: unknown): error is ApiError {
|
||||
if (typeof error !== 'object' || error === null || !('error' in error)) {
|
||||
return false;
|
||||
}
|
||||
const errorProp = (error as { error: unknown }).error;
|
||||
if (typeof errorProp !== 'object' || errorProp === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
typeof error === 'object' &&
|
||||
error !== null &&
|
||||
'error' in error &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
typeof (error as ApiError).error === 'object' &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
'message' in (error as ApiError).error
|
||||
'code' in errorProp &&
|
||||
typeof errorProp.code === 'number' &&
|
||||
'message' in errorProp &&
|
||||
typeof errorProp.message === 'string' &&
|
||||
'status' in errorProp &&
|
||||
typeof errorProp.status === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
export function isStructuredError(error: unknown): error is StructuredError {
|
||||
return (
|
||||
typeof error === 'object' &&
|
||||
error !== null &&
|
||||
'message' in error &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
typeof (error as StructuredError).message === 'string'
|
||||
);
|
||||
if (typeof error !== 'object' || error === null || !('message' in error)) {
|
||||
return false;
|
||||
}
|
||||
if (typeof error.message !== 'string') {
|
||||
return false;
|
||||
}
|
||||
if ('status' in error && typeof error.status !== 'number') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user