{"record":{"id":"6e3b62f7a9262a6a","repo":"linshenkx/prompt-optimizer","slug":"templateid","errorCode":null,"errorMessage":"${templateId}","messagePattern":"\\$\\{templateId\\}","errorType":"exception","errorClass":"EvaluationTemplateError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":573,"sourceCode":"   */\n  private async validateModel(modelKey: string): Promise<TextModelConfig> {\n    const model = await this.modelManager.getModel(modelKey);\n    if (!model) {\n      throw new EvaluationModelError(modelKey);\n    }\n    return model;\n  }\n\n  /**\n   * 获取评估模板\n   */\n  private async getEvaluationTemplate(type: EvaluationType, mode: EvaluationModeConfig): Promise<Template> {\n    const templateId = this.getTemplateId(type, mode);\n\n    try {\n      const template = await this.templateManager.getTemplate(templateId);\n      if (!template?.content) {\n        throw new EvaluationTemplateError(templateId);\n      }\n      return template;\n    } catch (error) {\n      if (error instanceof EvaluationTemplateError) {\n        throw error;\n      }\n      throw new EvaluationTemplateError(templateId);\n    }\n  }\n\n  /**\n   * 根据评估类型和模式获取模板ID\n   */\n  private getTemplateId(type: EvaluationType, mode: EvaluationModeConfig): string {\n    return `evaluation-${mode.functionMode}-${mode.subMode}-${type}`;\n  }\n\n  /**","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L555-L591","documentation":"EvaluationTemplateError is thrown by getEvaluationTemplate when the template for the computed templateId exists but has no content, or when the underlying lookup throws a non-EvaluationTemplateError. The message is the templateId; code is TEMPLATE_NOT_FOUND with params.context = templateId. Evaluation templates are selected per (evaluationType, mode.functionMode, mode.subMode).","triggerScenarios":"Calling evaluate/evaluateStream or the template() accessor where templateManager.getTemplate(templateId) resolves to null/undefined or a template whose content is empty — e.g. built-in evaluation templates were not registered or a custom mode combination has no template.","commonSituations":"Skipping template registration during service bootstrap; upgrading the library where template ids changed; custom functionMode/subMode combos that no bundled template covers; template stored in DB with empty content.","solutions":["Register the built-in evaluation templates (or your custom template) with TemplateManager for the failing templateId","Check that the template record actually has non-empty content","Verify functionMode/subMode values map to an existing template id via getTemplateId","Re-seed template data after upgrades that change template ids"],"exampleFix":"// before\nconst svc = new EvaluationService({ templateManager }); // templates never registered\nawait svc.evaluate(req);\n\n// after\nawait templateManager.registerTemplate(builtinEvaluationTemplates);\nconst svc = new EvaluationService({ templateManager });\nawait svc.evaluate(req);","handlingStrategy":"try-catch","validationCode":"const t = await templateManager.getTemplate(expectedTemplateId);\nif (!t?.content) throw new Error(`Template '${expectedTemplateId}' missing; register built-ins`);","typeGuard":null,"tryCatchPattern":"try { await svc.evaluate(req); } catch (e) { if (e instanceof EvaluationTemplateError) { await seedBuiltinTemplates(); return svc.evaluate(req); } throw e; }","preventionTips":["Register/seed evaluation templates during service bootstrap","Smoke-test getEvaluationTemplate for each (type, mode) you support after upgrades"],"tags":["evaluation","template","config","not-found"],"backgroundTag":"resource-template-missing","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}