{"record":{"id":"c61f30aba30419d5","repo":"linshenkx/prompt-optimizer","slug":"template-templateid-not-found-or-empty-c61f30","errorCode":null,"errorMessage":"Template \"${templateId}\" not found or empty.","messagePattern":"Template \"(.+?)\" not found or empty\\.","errorType":"exception","errorClass":"VariableValueGenerationExecutionError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/variable-value-generation/service.ts","lineNumber":116,"sourceCode":"   * 验证模型是否存在\n   */\n  private async validateModel(modelKey: string): Promise<void> {\n    const model = await this.modelManager.getModel(modelKey);\n    if (!model) {\n      throw new VariableValueGenerationModelError(modelKey);\n    }\n  }\n\n  /**\n   * 获取变量值生成模板\n   */\n  private async getGenerationTemplate(): Promise<Template> {\n    const templateId = 'variable-value-generation';\n\n    try {\n      const template = await this.templateManager.getTemplate(templateId);\n      if (!template?.content) {\n        throw new VariableValueGenerationExecutionError(`Template \"${templateId}\" not found or empty.`);\n      }\n      return template;\n    } catch (error) {\n      if (error instanceof VariableValueGenerationError) {\n        throw error\n      }\n      if (typeof (error as any)?.code === 'string') {\n        throw toErrorWithCode(error)\n      }\n      throw new VariableValueGenerationExecutionError(\n        `Failed to get template \"${templateId}\": ${error instanceof Error ? error.message : String(error)}`,\n      )\n    }\n  }\n\n  /**\n   * 构建模板上下文\n   */","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/variable-value-generation/service.ts#L98-L134","documentation":"The value-generation service renders the built-in template with id 'variable-value-generation' from the template manager. If getTemplate returns nothing or the template has empty content, VariableValueGenerationExecutionError is thrown because the LLM prompt cannot be constructed.","triggerScenarios":"Calling generate() when the template manager has no template named 'variable-value-generation', or the template exists but its content is '' / whitespace.","commonSituations":"Fresh install where the bundled template was never seeded; user edited/deleted the template in the template manager UI; template storage pointing at a stale/missing directory; template sync migration skipped in an upgrade; empty template file created by a failed write.","solutions":["Check the template manager for id 'variable-value-generation' and inspect its content","Restore/re-import the default template from the library's bundled defaults or reinstall/reseed templates","Verify the template storage path/env config used by templateManager is correct","If you intentionally customize it, ensure the saved content is non-empty after edits"],"exampleFix":"// before\nawait gen.generate(req); // throws Template \"variable-value-generation\" not found or empty.\n\n// after\nconst t = await templateManager.getTemplate('variable-value-generation');\nif (!t?.content) {\n  await templateManager.saveTemplate({\n    id: 'variable-value-generation',\n    content: DEFAULT_GENERATION_TEMPLATE_CONTENT, // bundled default\n  });\n}\nawait gen.generate(req);","handlingStrategy":"validation","validationCode":"const t = await templateManager.getTemplate('variable-value-generation');\nif (!t?.content?.trim()) throw new Error('generation template missing — reseed defaults');","typeGuard":null,"tryCatchPattern":"catch (e) { if (e instanceof VariableValueGenerationExecutionError && /not found or empty/.test(e.message)) { await reseedDefaultTemplates(); return gen.generate(req); } throw e; }","preventionTips":["Seed/verify built-in templates during app installation and migrations","Block template-editor saves that would leave content empty"],"tags":["template-config","missing-resource","variable-value-generation"],"backgroundTag":"template-not-found","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}