{"record":{"id":"b96edee46753a9bc","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-create-text-based-on-template","errorCode":null,"errorMessage":"unable to create text based on template","messagePattern":"unable to create text based on template","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/template/render.go","lineNumber":131,"sourceCode":"\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}\n","sourceCodeStart":113,"sourceCodeEnd":142,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/template/render.go#L113-L142","documentation":"After a template parses successfully, execute() runs tmpl.Execute against the template context. When execution fails (e.g. calling a method on nil, a function returning an error, index out of range at runtime) the renderer logs the cause and throws the generic 'unable to create text based on template'.","triggerScenarios":"A syntactically valid template whose execution panics or errors: invoking a template function with bad arguments (like random on wrong input), accessing fields of a nil pointer, wrong argument counts to funcs, or errors returned by custom funcs.","commonSituations":"Calling functions with invalid arguments at render time; template referencing properties absent on the segment's context in a way that errors rather than yielding <no value>; version changes that altered template context fields.","solutions":["Inspect the log output immediately preceding the error for the real execution cause","Run `oh-my-posh debug` to see which segment/template fails at runtime","Fix function arguments in the template (types, counts, values)","Guard risky property accesses with `if` checks or default values","Pin/upgrade oh-my-posh if a context field changed between versions"],"exampleFix":"// before\n{{ random .MaybeNilList }}\n// after\n{{ if .MaybeNilList }}{{ random .MaybeNilList }}{{ end }}","handlingStrategy":"try-catch","validationCode":"// pre-render check: exercise the template in debug mode\noh-my-posh debug  # shows the underlying execution error per segment","typeGuard":null,"tryCatchPattern":"// catch and fall back to a safe static prompt\nout, err := renderer.render(text)\nif err != nil {\n    if err.Error() == \"unable to create text based on template\" {\n        out = fallbackText\n    }\n}","preventionTips":["Guard nil-able properties with if checks in templates","Match function signatures exactly (arg types/counts)","Run `oh-my-posh debug` when changing template context usage","Check changelogs for template context field renames when upgrading"],"tags":["template","runtime-error","execution","go"],"backgroundTag":"template-execution-error","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}