linshenkx/prompt-optimizer · error · VariableExtractionExecutionError
Failed to get template "${templateId}": ${error instanceof E
Error message
Failed to get template "${templateId}": ${error instanceof Error ? error.message : String(error)} What it means
Wrapped error thrown when the underlying TemplateManager.getTemplate('variable-extraction') call itself throws an unexpected (non-structured) error — e.g. an I/O failure, a store connection error, or any exception without a machine-readable code. The original message is embedded so the root cause is not lost.
Source
Thrown at packages/core/src/services/variable-extraction/service.ts:137
*/
private async getExtractionTemplate(): Promise<Template> {
const templateId = 'variable-extraction';
try {
const template = await this.templateManager.getTemplate(templateId);
if (!template?.content) {
throw new VariableExtractionExecutionError(`Template "${templateId}" not found or empty.`);
}
return template;
} catch (error) {
if (error instanceof VariableExtractionError) {
throw error
}
// Preserve structured template errors if possible (code/params).
if (typeof (error as any)?.code === 'string') {
throw toErrorWithCode(error)
}
throw new VariableExtractionExecutionError(
`Failed to get template "${templateId}": ${error instanceof Error ? error.message : String(error)}`,
)
}
}
/**
* 构建模板上下文
*/
private buildTemplateContext(request: VariableExtractionRequest): TemplateContext {
const context: TemplateContext = {
promptContent: request.promptContent,
existingVariableNames: request.existingVariableNames?.join(', ') || 'None',
hasExistingVariables: !!request.existingVariableNames?.length,
};
return context;
}
View on GitHub (pinned to 3e677b1d9f)
Solutions
- Read the embedded message — it is the root cause from the TemplateManager; fix that (permissions, connectivity, store config).
- Verify the TemplateManager's backing store (files/DB/HTTP) is reachable and healthy.
- Check file permissions on the templates directory if using file-based storage.
- Clear/rebuild the template cache if it may be corrupted.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await extractionService.extract({ modelKey, content });
} catch (e) {
if (e instanceof VariableExtractionExecutionError && e.message.startsWith('Failed to get template')) {
// inspect embedded root cause; likely template store I/O — retry after restoring the store
}
throw e;
} Prevention
- Monitor template store (files/DB) health and add it to startup checks.
- Wrap TemplateManager with retries or circuit breaking for transient I/O failures.
- Log the full wrapped message — it carries the underlying error text for diagnosis.
When it happens
Trigger: TemplateManager.getTemplate throws for reasons other than 'not found': filesystem read errors, a database/HTTP template store being unreachable, deserialization bugs, or any thrown value that is not a VariableExtractionError and has no string code field. Structured errors with a code are re-thrown as-is; only uncoded ones become this wrapper.
Common situations: Template store backed by a DB/remote service that is down; permission errors reading the templates directory in a hardened container; corrupted template cache; version upgrade changed the template storage format causing loader exceptions.
Related errors
- Iteration failed: ${errorMessage}
- Sub mode must not be empty.
- ${templateId}
- STORAGE_ERROR
- Failed to add favorite: ${errorMessage}
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/4eec15f214909122.
Report an issue: GitHub.