{"record":{"id":"e2ba2d8fa4d5139a","repo":"linshenkx/prompt-optimizer","slug":"test-failed-errormessage","errorCode":null,"errorMessage":"Test failed: ${errorMessage}","messagePattern":"Test failed: (.+?)","errorType":"exception","errorClass":"TestError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/prompt/service.ts","lineNumber":431,"sourceCode":"\n      const messages: Message[] = [];\n\n      // 只有当 systemPrompt 不为空时才添加 system 消息\n      if (systemPrompt?.trim()) {\n        messages.push({ role: \"system\", content: systemPrompt });\n      }\n\n      messages.push({ role: \"user\", content: userPrompt });\n\n      const result = await this.llmService.sendMessage(messages, modelKey);\n\n      // 注意：测试功能不保存历史记录，保持架构一致性\n      // 测试是临时性验证，不应与优化历史记录混合\n\n      return result;\n    } catch (error) {\n      const errorMessage = this.getSafeTestErrorMessage(error, inputImages);\n      throw new TestError(\n        systemPrompt,\n        userPrompt,\n        `Test failed: ${errorMessage}`,\n      );\n    }\n  }\n\n  /**\n   * 获取历史记录\n   */\n  async getHistory(): Promise<PromptRecord[]> {\n    return await this.historyManager.getRecords();\n  }\n\n  /**\n   * 获取迭代链\n   */\n  async getIterationChain(recordId: string): Promise<PromptRecord[]> {","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/prompt/service.ts#L413-L449","documentation":"The outer catch of testPrompt: any error thrown during test execution (model call, image understanding, streaming setup) is converted via getSafeTestErrorMessage and re-thrown as TestError prefixed 'Test failed:'. getSafeTestErrorMessage sanitizes messages, particularly when input images are present, to avoid leaking sensitive content.","triggerScenarios":"Provider API errors (auth, quota, rate limit), network failures, image-understanding service errors when inputImages are provided, or invalid model responses during the test call — all caught and wrapped here.","commonSituations":"Running a quick test with an invalid API key; oversized/unreadable image inputs triggering image-service failures; transient provider outages during manual testing.","solutions":["Inspect the wrapped message (after 'Test failed:') for the sanitized root cause and fix that (credentials, quota, image format)","Retry once for transient network/provider errors","Validate image references with the image service before passing inputImages","Confirm the model config's API endpoint and credentials are current"],"exampleFix":"// before\nconst out = await promptService.testPrompt(sys, user, modelKey);\n\n// after\ntry {\n  const out = await promptService.testPrompt(sys, user, modelKey);\n} catch (e) {\n  if (e instanceof TestError) {\n    showUserToast(e.message); // sanitized, safe to display\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  const out = await promptService.testPrompt(sys, user, modelKey);\n} catch (e) {\n  if (e instanceof TestError) {\n    showUser(e.message); // sanitized by getSafeTestErrorMessage\n    if (isTransient(e.message)) retry();\n  } else throw e;\n}","preventionTips":["Surface sanitized TestError messages directly to users","Pre-validate image refs before passing inputImages","Keep provider credentials and quotas monitored"],"tags":["wrapper-error","test-prompt","model-call","image-input"],"backgroundTag":"wrapped-downstream-failure","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}