JanDeDobbeleer/oh-my-posh · error

unable to create text based on template

Error message

unable to create text based on template

What it means

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'.

Solutions

  1. Inspect the log output immediately preceding the error for the real execution cause
  2. Run `oh-my-posh debug` to see which segment/template fails at runtime
  3. Fix function arguments in the template (types, counts, values)
  4. Guard risky property accesses with `if` checks or default values
  5. Pin/upgrade oh-my-posh if a context field changed between versions

Example fix

// before
{{ random .MaybeNilList }}
// after
{{ if .MaybeNilList }}{{ random .MaybeNilList }}{{ end }}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-render check: exercise the template in debug mode
oh-my-posh debug  # shows the underlying execution error per segment

Try / catch

// catch and fall back to a safe static prompt
out, err := renderer.render(text)
if err != nil {
    if err.Error() == "unable to create text based on template" {
        out = fallbackText
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/b96edee46753a9bc. Report an issue: GitHub.

Appendix: source

Thrown at src/template/render.go:131

	// Store; if another goroutine already stored an equivalent template, use theirs.
	actual, _ := parsedTemplates.LoadOrStore(key, tmpl)
	return actual.(*template.Template), nil
}

func (t *renderer) execute(text *Text) (string, error) {
	tmpl, err := parsedTemplate(text)
	if err != nil {
		log.Error(err)
		return "", errors.New(InvalidTemplate)
	}

	t.context.init(text)

	err = tmpl.Execute(&t.buffer, t.context)
	if err != nil {
		log.Error(err)
		return "", errors.New(IncorrectTemplate)
	}

	output := t.buffer.String()

	// issue with missingkey=zero ignored for map[string]any
	// https://github.com/golang/go/issues/24963
	output = strings.ReplaceAll(output, "<no value>", "")

	return output, nil
}

View on GitHub (pinned to 0976794618)