{"record":{"id":"69a79d1efbefde3b","repo":"JanDeDobbeleer/oh-my-posh","slug":"invalid-template-text","errorCode":null,"errorMessage":"invalid template text","messagePattern":"invalid template text","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/template/render.go","lineNumber":123,"sourceCode":"\t// Cache miss: patch the raw template into its executable form.\n\ttext.patchTemplate()\n\n\t// Parse into a fresh template with the func map matching this render's trust level.\n\ttmpl, err := template.New(\"cache\").Funcs(funcMap(text.trusted)).Parse(text.template)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Store; if another goroutine already stored an equivalent template, use theirs.\n\tactual, _ := parsedTemplates.LoadOrStore(key, tmpl)\n\treturn actual.(*template.Template), nil\n}\n\nfunc (t *renderer) execute(text *Text) (string, error) {\n\ttmpl, err := parsedTemplate(text)\n\tif err != nil {\n\t\tlog.Error(err)\n\t\treturn \"\", errors.New(InvalidTemplate)\n\t}\n\n\tt.context.init(text)\n\n\terr = tmpl.Execute(&t.buffer, t.context)\n\tif err != nil {\n\t\tlog.Error(err)\n\t\treturn \"\", errors.New(IncorrectTemplate)\n\t}\n\n\toutput := t.buffer.String()\n\n\t// issue with missingkey=zero ignored for map[string]any\n\t// https://github.com/golang/go/issues/24963\n\toutput = strings.ReplaceAll(output, \"<no value>\", \"\")\n\n\treturn output, nil\n}","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/template/render.go#L105-L141","documentation":"The template renderer wraps text/template parsing. execute() calls parsedTemplate, and when the template text fails to parse (syntax error: unbalanced {{ }}, unknown function, bad pipeline) it logs the underlying cause and replaces it with the generic error 'invalid template text'.","triggerScenarios":"Any prompt segment template string that fails template.Parse — malformed Go template syntax, unclosed actions, unknown function names (e.g. calling `random` when not in the func map for the trust level), or invalid characters in the template.","commonSituations":"Hand-edited prompt config with a missing `{{ end }}`; copied a template using functions unavailable at the segment's trust level; escaping issues in TOML/YAML config mangling the template string.","solutions":["Check the oh-my-posh debug/log output for the underlying parse error logged just before the generic message","Validate template syntax: balance all {{ }} actions and `{{ end }}` blocks","Confirm every function used exists for that template's trust level","Test the template with `oh-my-posh debug` to see per-segment rendering errors","Escape literal braces in config files if the format requires it"],"exampleFix":"// before\n{{ if .Segments.Flags }}...  (missing end)\n// after\n{{ if .Segments.Flags }}...{{ end }}","handlingStrategy":"validation","validationCode":"// validate template syntax before shipping it in config\noh-my-posh debug  # per-segment template errors are reported here","typeGuard":null,"tryCatchPattern":"// consuming code should treat the generic error as a parse failure and log the template text\nif _, err := render(text); err != nil {\n    if err.Error() == \"invalid template text\" {\n        log.Printf(\"bad template: %q\", text)\n    }\n}","preventionTips":["Balance every {{ }} action with {{ end }}","Run `oh-my-posh debug` after editing templates","Check function availability for the template's trust level","Edit templates in small increments to isolate syntax mistakes"],"tags":["template","parse-error","go-template"],"backgroundTag":"template-parse-error","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}