JanDeDobbeleer/oh-my-posh · error

invalid template text

Error message

invalid template text

What it means

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

Source

Thrown at src/template/render.go:123

	// Cache miss: patch the raw template into its executable form.
	text.patchTemplate()

	// Parse into a fresh template with the func map matching this render's trust level.
	tmpl, err := template.New("cache").Funcs(funcMap(text.trusted)).Parse(text.template)
	if err != nil {
		return nil, err
	}

	// 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)

Solutions

  1. Check the oh-my-posh debug/log output for the underlying parse error logged just before the generic message
  2. Validate template syntax: balance all {{ }} actions and `{{ end }}` blocks
  3. Confirm every function used exists for that template's trust level
  4. Test the template with `oh-my-posh debug` to see per-segment rendering errors
  5. Escape literal braces in config files if the format requires it

Example fix

// before
{{ if .Segments.Flags }}...  (missing end)
// after
{{ if .Segments.Flags }}...{{ end }}
Defensive patterns

Strategy: validation

Validate before calling

// validate template syntax before shipping it in config
oh-my-posh debug  # per-segment template errors are reported here

Try / catch

// consuming code should treat the generic error as a parse failure and log the template text
if _, err := render(text); err != nil {
    if err.Error() == "invalid template text" {
        log.Printf("bad template: %q", text)
    }
}

Prevention

When it happens

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

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

Related errors


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