Repository navigation
fix(core): improve debug txt diagnostics #6277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8dfbf57
6ab7028
f1ec1d2
547f004
cd7dbe8
e8a922d
47a6932
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,12 +6,25 @@ | |||||||||
|
|
||||||||||
| import type { GenerateContentParameters } from '@google/genai'; | ||||||||||
| import { createDebugLogger } from '../../utils/debugLogger.js'; | ||||||||||
| import { getErrorStatus, getErrorType } from '../../utils/errors.js'; | ||||||||||
| import { getRateLimitErrorDetails } from '../../utils/rateLimit.js'; | ||||||||||
| import { redactProxyError } from '../../utils/runtimeFetchOptions.js'; | ||||||||||
| import type { ErrorHandler, RequestContext } from './types.js'; | ||||||||||
|
|
||||||||||
| const debugLogger = createDebugLogger('OPENAI_ERROR'); | ||||||||||
| export type { ErrorHandler } from './types.js'; | ||||||||||
|
|
||||||||||
| interface ApiErrorDiagnostics { | ||||||||||
| model: string; | ||||||||||
| durationMs: number; | ||||||||||
| errorType: string; | ||||||||||
| statusCode?: number; | ||||||||||
| providerCode?: string; | ||||||||||
| providerMessage?: string; | ||||||||||
| requestId?: string; | ||||||||||
| transport?: 'http' | 'sse' | 'unknown'; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export class EnhancedErrorHandler implements ErrorHandler { | ||||||||||
| constructor( | ||||||||||
| private shouldSuppressLogging: ( | ||||||||||
|
|
@@ -35,7 +48,11 @@ export class EnhancedErrorHandler implements ErrorHandler { | |||||||||
|
|
||||||||||
| // Allow subclasses to suppress error logging for specific scenarios | ||||||||||
| if (!this.shouldSuppressErrorLogging(redactedError, request)) { | ||||||||||
| debugLogger.error('OpenAI API Error:', errorMessage); | ||||||||||
| debugLogger.error( | ||||||||||
| 'OpenAI API Error:', | ||||||||||
| errorMessage, | ||||||||||
| this.buildDiagnostics(redactedError, context), | ||||||||||
| ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Provide helpful timeout-specific error message | ||||||||||
|
|
@@ -98,6 +115,51 @@ export class EnhancedErrorHandler implements ErrorHandler { | |||||||||
| return error instanceof Error ? error.message : String(error); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private buildDiagnostics( | ||||||||||
| error: unknown, | ||||||||||
| context: RequestContext, | ||||||||||
| ): ApiErrorDiagnostics { | ||||||||||
| const details = getRateLimitErrorDetails(error); | ||||||||||
| const requestId = this.getRequestId(error) ?? details.requestId; | ||||||||||
| return { | ||||||||||
| model: context.model, | ||||||||||
| durationMs: Date.now() - context.startTime, | ||||||||||
| errorType: getErrorType(error), | ||||||||||
| ...(getErrorStatus(error) !== undefined | ||||||||||
| ? { statusCode: getErrorStatus(error) } | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion]
Suggested change
Or compute it once before the return: const statusCode = getErrorStatus(error);— qwen3.7-max via Qwen Code /review |
||||||||||
| : {}), | ||||||||||
| ...(details.providerCode !== undefined | ||||||||||
| ? { providerCode: details.providerCode } | ||||||||||
| : {}), | ||||||||||
| ...(details.providerMessage !== undefined | ||||||||||
| ? { providerMessage: details.providerMessage } | ||||||||||
| : {}), | ||||||||||
| ...(requestId !== undefined ? { requestId } : {}), | ||||||||||
| ...(details.transport !== 'unknown' | ||||||||||
| ? { transport: details.transport } | ||||||||||
| : {}), | ||||||||||
| }; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private getRequestId(error: unknown): string | undefined { | ||||||||||
| if (!error || typeof error !== 'object') return undefined; | ||||||||||
| const source = error as { | ||||||||||
| requestID?: unknown; | ||||||||||
| request_id?: unknown; | ||||||||||
| response_id?: unknown; | ||||||||||
| }; | ||||||||||
| for (const value of [ | ||||||||||
| source.requestID, | ||||||||||
| source.request_id, | ||||||||||
| source.response_id, | ||||||||||
| ]) { | ||||||||||
| if (typeof value === 'string' && value) { | ||||||||||
| return value; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| return undefined; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private getTimeoutTroubleshootingTips(): string { | ||||||||||
| const tips = [ | ||||||||||
| '- Reduce input length or complexity', | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.