{"record":{"id":"20bac1550882e886","repo":"linshenkx/prompt-optimizer","slug":"template-templateid-not-found-or-empty","errorCode":null,"errorMessage":"Template \"${templateId}\" not found or empty.","messagePattern":"Template \"(.+?)\" not found or empty\\.","errorType":"exception","errorClass":"VariableExtractionExecutionError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/variable-extraction/service.ts","lineNumber":126,"sourceCode":"   * 验证模型存在性\n   */\n  private async validateModel(modelKey: string): Promise<void> {\n    const model = await this.modelManager.getModel(modelKey);\n    if (!model) {\n      throw new VariableExtractionModelError(modelKey);\n    }\n  }\n\n  /**\n   * 获取提示词模板 (统一模板)\n   */\n  private async getExtractionTemplate(): Promise<Template> {\n    const templateId = 'variable-extraction';\n\n    try {\n      const template = await this.templateManager.getTemplate(templateId);\n      if (!template?.content) {\n        throw new VariableExtractionExecutionError(`Template \"${templateId}\" not found or empty.`);\n      }\n      return template;\n    } catch (error) {\n      if (error instanceof VariableExtractionError) {\n        throw error\n      }\n      // Preserve structured template errors if possible (code/params).\n      if (typeof (error as any)?.code === 'string') {\n        throw toErrorWithCode(error)\n      }\n      throw new VariableExtractionExecutionError(\n        `Failed to get template \"${templateId}\": ${error instanceof Error ? error.message : String(error)}`,\n      )\n    }\n  }\n\n  /**\n   * 构建模板上下文","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/variable-extraction/service.ts#L108-L144","documentation":"The variable-extraction service requires a prompt template with id 'variable-extraction' to be loaded from the TemplateManager. This error means the template lookup returned an object with no content (or nothing at all), so extraction cannot proceed because there is no prompt to send to the LLM.","triggerScenarios":"Calling extract() when the TemplateManager has no template registered under the id 'variable-extraction', or the registered template exists but its content field is null/empty string. Typically happens when template loading/registration is skipped or the template bundle is incomplete.","commonSituations":"Template files missing from the deployment bundle (packaging excluded the templates dir); templates loaded from a directory where variable-extraction.md was renamed or deleted; template registered under a different id (e.g. 'variable_extraction' with underscore); content loaded but empty due to a failed file read that was swallowed.","solutions":["Check the TemplateManager contains a template with the exact id 'variable-extraction' and that its content is a non-empty string.","Restore or re-add the missing template file/entry to whatever source the TemplateManager loads from.","If you renamed the template, either rename it back or register an alias under 'variable-extraction'.","Log await templateManager.getTemplate('variable-extraction') before extract() to inspect what is actually returned."],"exampleFix":"// before\nconst result = await extractionService.extract({ modelKey, content });\n\n// after\nconst tpl = await templateManager.getTemplate('variable-extraction');\nif (!tpl?.content) throw new Error('variable-extraction template missing — check template registration');\nconst result = await extractionService.extract({ modelKey, content });","handlingStrategy":"validation","validationCode":"const tpl = await templateManager.getTemplate('variable-extraction');\nif (!tpl?.content) {\n  throw new Error('variable-extraction template not loaded — check template registration');\n}\nconst result = await extractionService.extract({ modelKey, content });","typeGuard":"const hasTemplateContent = (t: unknown): t is { content: string } =>\n  !!t && typeof t === 'object' && typeof (t as any).content === 'string' && (t as any).content.length > 0;","tryCatchPattern":"try {\n  await extractionService.extract({ modelKey, content });\n} catch (e) {\n  if (e instanceof VariableExtractionExecutionError && /not found or empty/.test(e.message)) {\n    // template not registered: fix template setup\n  }\n  throw e;\n}","preventionTips":["Assert required templates exist during application startup, not lazily at first request.","Include template files in the deployment bundle and verify with a boot-time smoke check.","Pin the exact template id 'variable-extraction' via a shared constant to avoid drift."],"tags":["template","configuration","prompt","variable-extraction"],"backgroundTag":"missing-template","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}