linshenkx/prompt-optimizer · error · APIError
Unknown error
Error message
Unknown error
What it means
Terminal fallback in getModelsAsync's catch chain: the caught error had no recognizable message (falsy error.message), no response data, and no network markers, so the adapter throws APIError('Unknown error'). It usually indicates an exception thrown by something other than the HTTP call itself.
Source
Thrown at packages/core/src/services/llm/adapters/openai-adapter.ts:187
// 连接错误处理(包括跨域检测)
if (error.message && (error.message.includes('Failed to fetch') ||
error.message.includes('Connection error'))) {
const isCrossOriginError = this.detectCrossOriginError(error, baseURL)
if (isCrossOriginError) {
throw new APIError(`Cross-origin connection failed: ${error.message}`)
} else {
throw new APIError(`Connection failed: ${error.message}`)
}
}
// API返回的错误信息
if (error.response?.data) {
throw new APIError(`API error: ${JSON.stringify(error.response.data)}`)
}
// 其他错误,保持原始信息
throw new APIError(error.message || 'Unknown error')
}
}
// ===== 参数定义(用于buildDefaultModel) =====
/**
* 获取参数定义
* 基于 OpenAI 官方文档: https://platform.openai.com/docs/api-reference/chat/create
*/
protected getParameterDefinitions(_modelId: string): readonly ParameterDefinition[] {
return [
{
name: 'reasoning_effort',
labelKey: 'params.reasoning_effort.label',
descriptionKey: 'params.reasoning_effort.description',
description: 'Reasoning effort for GPT-5.6 models.',
type: 'string',
defaultValue: 'none',View on GitHub (pinned to 3e677b1d9f)
Solutions
- Reproduce with verbose logging around the getModelsAsync call to find what was actually thrown
- Upgrade the core package in case the empty-message bug was fixed
- Wrap call sites to log the raw caught value (not just .message)
- File an issue with the stack trace if it originates inside the adapter
Example fix
// before
catch (e: any) { throw new APIError(e.message || 'Unknown error') }
// after
catch (e: any) {
console.error('raw error:', e)
throw new APIError(e?.message || e?.toString() || 'Unknown error')
} Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try { models = await adapter.getModelsAsync() }
catch (e) {
if (e instanceof APIError && e.message === 'Unknown error') { captureRawErrorDiagnostics(); models = [] }
else throw e
} Prevention
- Log the raw thrown value, not just .message, at call sites
- Keep the core package updated
- Add integration tests covering model listing for each provider
When it happens
Trigger: A bug or non-Error throw inside the try block (undefined variable, JSON parse of unexpected input that throws without message), SDK internals throwing empty errors, or aborted requests in some runtimes.
Common situations: Runtime/edge-case bugs in adapter code paths, aborted fetches in tests, objects thrown instead of Error.
Related errors
- UNSUPPORTED_TEST_TYPE
- API returned empty model list
- Unexpected API response format
- Cross-origin connection failed: ${error.message}
- Connection failed: ${error.message}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/095b1bd3ec4e253a.
Report an issue: GitHub.