JanDeDobbeleer/oh-my-posh · error

failed to parse recorded theme %s: %w

Error message

failed to parse recorded theme %s: %w

What it means

This error is thrown by recordThemeSanitized in the oh-my-posh CLI (`oh-my-posh config export data --themes ... --sanitize`). After a theme file is sanitized, the resulting JSON is unmarshalled into a map of raw JSON messages; if json.Unmarshal rejects the sanitized bytes, this error wraps the parse failure with the theme path. It means a theme failed to produce a valid JSON top-level object even after sanitization.

Source

Thrown at src/cli/config_export_data.go:238

	if _, err := render.Config(cfg, 120, true, func(flags *runtime.Flags) error {
		return applyDataFile(flags, func(string) bool { return false })
	}); err != nil {
		return nil, nil, fmt.Errorf("failed to record theme %s: %w", themePath, err)
	}

	doc, err := buildDataDocument(cfg)
	if err != nil {
		return nil, nil, fmt.Errorf("failed to record theme %s: %w", themePath, err)
	}

	sanitized, err := sanitizeDataDocument(doc, cfg)
	if err != nil {
		return nil, nil, fmt.Errorf("failed to sanitize theme %s: %w", themePath, err)
	}

	var root map[string]json.RawMessage
	if err := json.Unmarshal(sanitized, &root); err != nil {
		return nil, nil, fmt.Errorf("failed to parse recorded theme %s: %w", themePath, err)
	}

	if raw, ok := root[config.DataEnvKey]; ok {
		if err := json.Unmarshal(raw, &env); err != nil {
			return nil, nil, fmt.Errorf("failed to parse env for theme %s: %w", themePath, err)
		}
	}

	if raw, ok := root[config.DataSegmentsKey]; ok {
		if err := json.Unmarshal(raw, &segments); err != nil {
			return nil, nil, fmt.Errorf("failed to parse segments for theme %s: %w", themePath, err)
		}
	}

	return env, segments, nil
}

// countPopulatedLeaves parses raw and counts its non-zero-value leaves: a

View on GitHub (pinned to 0976794618)

Solutions

  1. Run `oh-my-posh config validate --config <themePath>` on the theme named in the message and fix the JSON syntax error it reports
  2. Open the theme file at the reported path and validate it with a JSON linter (jq, python -m json.tool) to locate the malformed section
  3. Re-download the theme from the official themes directory instead of editing a possibly corrupted copy
  4. If the file is valid JSON but the error persists, re-run with --sanitize off to confirm, then report the sanitizer bug upstream with the theme attached

Example fix

// before: theme file with trailing comma
{ "blocks": [ { "type": "prompt", }, ], }
// after
{ "blocks": [ { "type": "prompt" } ] }
Defensive patterns

Strategy: validation

Validate before calling

path := "themes/mytheme.omp.json"
raw, err := os.ReadFile(path)
if err != nil { return err }
var v any
if err := json.Unmarshal(raw, &v); err != nil {
    return fmt.Errorf("%s is not valid JSON: %w", path, err)
}
if _, ok := v.(map[string]any); !ok {
    return fmt.Errorf("%s: top level must be a JSON object", path)
}

Type guard

func isValidJSONObject(b []byte) bool {
    var m map[string]json.RawMessage
    return json.Unmarshal(b, &m) == nil
}

Try / catch

doc, err := recordThemeSanitized(themePath)
if err != nil {
    var perr *json.SyntaxError
    if errors.As(err, &perr) {
        log.Fatalf("theme %s: JSON syntax error at offset %d: %v", themePath, perr.Offset, perr)
    }
    return err
}

Prevention

When it happens

Trigger: Running `oh-my-posh config export data --themes <dir> --sanitize` where a theme in <dir>, after sanitization, is not a valid JSON object (malformed JSON in the theme file, or a sanitizer bug emitting invalid JSON).

Common situations: A hand-edited or downloaded theme in the themes directory contains syntax errors (trailing commas, unquoted keys); a theme file is truncated; the sanitizer produced invalid output for unusual glyphs/escapes.

Understand the failure class

Related errors


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