linshenkx/prompt-optimizer · error · TestError

Test failed: ${errorMessage}

Error message

Test failed: ${errorMessage}

What it means

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.

Source

Thrown at packages/core/src/services/prompt/service.ts:431

      const messages: Message[] = [];

      // 只有当 systemPrompt 不为空时才添加 system 消息
      if (systemPrompt?.trim()) {
        messages.push({ role: "system", content: systemPrompt });
      }

      messages.push({ role: "user", content: userPrompt });

      const result = await this.llmService.sendMessage(messages, modelKey);

      // 注意:测试功能不保存历史记录,保持架构一致性
      // 测试是临时性验证,不应与优化历史记录混合

      return result;
    } catch (error) {
      const errorMessage = this.getSafeTestErrorMessage(error, inputImages);
      throw new TestError(
        systemPrompt,
        userPrompt,
        `Test failed: ${errorMessage}`,
      );
    }
  }

  /**
   * 获取历史记录
   */
  async getHistory(): Promise<PromptRecord[]> {
    return await this.historyManager.getRecords();
  }

  /**
   * 获取迭代链
   */
  async getIterationChain(recordId: string): Promise<PromptRecord[]> {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Inspect the wrapped message (after 'Test failed:') for the sanitized root cause and fix that (credentials, quota, image format)
  2. Retry once for transient network/provider errors
  3. Validate image references with the image service before passing inputImages
  4. Confirm the model config's API endpoint and credentials are current

Example fix

// before
const out = await promptService.testPrompt(sys, user, modelKey);

// after
try {
  const out = await promptService.testPrompt(sys, user, modelKey);
} catch (e) {
  if (e instanceof TestError) {
    showUserToast(e.message); // sanitized, safe to display
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

try {
  const out = await promptService.testPrompt(sys, user, modelKey);
} catch (e) {
  if (e instanceof TestError) {
    showUser(e.message); // sanitized by getSafeTestErrorMessage
    if (isTransient(e.message)) retry();
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Running a quick test with an invalid API key; oversized/unreadable image inputs triggering image-service failures; transient provider outages during manual testing.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/e2ba2d8fa4d5139a. Report an issue: GitHub.