linshenkx/prompt-optimizer · error · VariableValueGenerationExecutionError
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
While fetching the 'variable-value-generation' template, the template manager threw an unexpected error (with no string code property and not already a VariableValueGenerationError). The service wraps it into VariableValueGenerationExecutionError with the original message appended. Typical causes are I/O or storage-layer failures rather than a missing template.
Source
Thrown at packages/core/src/services/variable-value-generation/service.ts:126
* 获取变量值生成模板
*/
private async getGenerationTemplate(): Promise<Template> {
const templateId = 'variable-value-generation';
try {
const template = await this.templateManager.getTemplate(templateId);
if (!template?.content) {
throw new VariableValueGenerationExecutionError(`Template "${templateId}" not found or empty.`);
}
return template;
} catch (error) {
if (error instanceof VariableValueGenerationError) {
throw error
}
if (typeof (error as any)?.code === 'string') {
throw toErrorWithCode(error)
}
throw new VariableValueGenerationExecutionError(
`Failed to get template "${templateId}": ${error instanceof Error ? error.message : String(error)}`,
)
}
}
/**
* 构建模板上下文
*/
private buildTemplateContext(request: VariableValueGenerationRequest): TemplateContext {
const formatVariables = (variables: VariableToGenerate[]): string => variables
.map((v, idx) => {
const parts = [`${idx + 1}. ${v.name}`];
if (v.description?.trim()) parts.push(`(description: ${v.description.trim()})`);
if (v.defaultValue?.trim()) parts.push(`(default value: ${v.defaultValue.trim()})`);
if (v.currentValue) parts.push(`(current value: ${v.currentValue})`);
if (v.source) parts.push(`[${v.source}]`);
return parts.join(' ');
})View on GitHub (pinned to 3e677b1d9f)
Solutions
- Read the appended original message in the error string — it identifies the storage failure
- Check filesystem permissions / DB connectivity for the template store
- Point template storage at a valid writable location (env/config) and restart
- Restore the template store from backup or reseed defaults if corrupted
- Note: errors with a string code property pass through unchanged — check that subtype for coded storage errors
Example fix
// before
await gen.generate(req);
// after
try {
await gen.generate(req);
} catch (e) {
if (e instanceof VariableValueGenerationExecutionError && e.message.includes('Failed to get template')) {
// storage-level issue: verify template store health before retrying
await assertTemplateStoreHealthy(templateManager);
}
throw e;
} Defensive patterns
Strategy: try-catch
Try / catch
catch (e) { if (e instanceof VariableValueGenerationExecutionError && e.message.startsWith('Failed to get template')) { const cause = e.message.split(':').slice(1).join(':').trim(); /* route to storage diagnostics based on cause */ } throw e; } Prevention
- Monitor template storage health (DB/file) alongside the app
- Distinguish coded storage errors (which pass through with .code) from wrapped ones when logging
When it happens
Trigger: templateManager.getTemplate('variable-value-generation') rejects due to a database connection error, file permission denied on the templates directory, corrupted template store, or an unserialized/corrupt template record.
Common situations: Templates stored in SQLite whose file is locked or corrupted; read-only filesystem in a container; template storage path env var pointing to a nonexistent/unwritable directory; a partially applied migration leaving corrupt rows.
Related errors
- error instanceof Error ? error.message : String(error)
- Template "${templateId}" not found or empty.
- Failed to get favorite details: ${errorMessage}
- Failed to update favorite: ${errorMessage}
- Failed to set favorite prompt asset current version: ${error
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/905497e18f630ff5.
Report an issue: GitHub.