{"record":{"id":"20c25137cbdd73f6","repo":"linshenkx/prompt-optimizer","slug":"sub-mode-must-not-be-empty","errorCode":null,"errorMessage":"Sub mode must not be empty.","messagePattern":"Sub mode must not be empty\\.","errorType":"validation","errorClass":"EvaluationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":464,"sourceCode":"    }\n  }\n\n  /**\n   * 验证评估请求\n   */\n  private validateRequest(request: EvaluationRequest): void {\n    if (!request.evaluationModelKey?.trim()) {\n      throw new EvaluationValidationError('Evaluation model key must not be empty.');\n    }\n\n    if (!request.mode) {\n      throw new EvaluationValidationError('Evaluation mode configuration must not be empty.');\n    }\n    if (!request.mode.functionMode) {\n      throw new EvaluationValidationError('Function mode must not be empty.');\n    }\n    if (!request.mode.subMode) {\n      throw new EvaluationValidationError('Sub mode must not be empty.');\n    }\n\n    switch (request.type) {\n      case 'result':\n        if (!request.target?.workspacePrompt?.trim()) {\n          throw new EvaluationValidationError('Workspace prompt must not be empty.');\n        }\n        this.validateTestCase(request.testCase, 'Result evaluation test case');\n        this.validateSnapshot(request.snapshot, 'Result evaluation snapshot');\n        if (request.snapshot.testCaseId !== request.testCase.id) {\n          throw new EvaluationValidationError(\n            'Result evaluation snapshot testCaseId must match testCase.id.'\n          );\n        }\n        if (this.isImageText2ImageMode(request) && !this.hasSnapshotOutputMedia(request.snapshot)) {\n          throw new EvaluationValidationError(\n            'Image result evaluation requires at least one output image evidence item.'\n          );","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L446-L482","documentation":"OptimizationError thrown by optimizeMessage when the template manager cannot produce a usable template: it looks up request.templateId or defaults to 'context-message-optimize', and if the template or its content is missing/empty it refuses to proceed. The LLM prompt for message optimization is template-driven, so a missing template is fatal to this flow.","triggerScenarios":"Calling optimizeMessage when the built-in 'context-message-optimize' template is not registered (template manager not initialized / templates not loaded), or when a custom request.templateId has no matching entry or has empty content.","commonSituations":"Skipping template-manager initialization in custom builds or tests, renaming/deleting the default template in a fork, templates loading async and the call racing them, or passing a stale templateId from settings after templates were reorganized.","solutions":["Initialize/await the template manager (ensure built-in templates are registered) before calling optimizeMessage.","If passing templateId, verify it exists: (await templateManager.getTemplate(templateId))?.content before the call.","After upgrading or forking, confirm the 'context-message-optimize' template is still bundled and registered.","Drop the templateId field to use the default when unsure."],"exampleFix":"// before\nawait promptService.optimizeMessage({ selectedMessageId: id, messages, modelKey, templateId: 'my-old-template' });\n\n// after\nconst request = { selectedMessageId: id, messages, modelKey }; // use default template\nawait promptService.optimizeMessage(request);","handlingStrategy":"validation","validationCode":"const tpl = await templateManager.getTemplate(request.templateId || 'context-message-optimize');\nif (!tpl?.content) throw new Error('Template unavailable');","typeGuard":"async function templateReady(tm: any, id?: string): Promise<boolean> {\n  const t = await tm.getTemplate(id || 'context-message-optimize');\n  return !!t?.content;\n}","tryCatchPattern":"try { await svc.optimizeMessage(req); } catch (e) { if (e instanceof OptimizationError && /Template not found/.test(e.message)) await templateManager.reload?.(); }","preventionTips":["Initialize template manager and register built-ins before use","Omit templateId to use the default","Verify custom templates exist after upgrades"],"tags":["template","message-optimization","not-found"],"backgroundTag":"template-not-found","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}