JanDeDobbeleer/oh-my-posh · error

failed to sanitize theme %s: %w

Error message

failed to sanitize theme %s: %w

What it means

Once a theme's document is built, recordThemeSanitized sanitizes it via sanitizeDataDocument (scrubbing identity fields). If sanitization fails, the theme is aborted with "failed to sanitize theme <path>: <reason>". The cause is internal to sanitizeDataDocument — typically it could not process the recorded document for this theme.

Source

Thrown at src/cli/config_export_data.go:233

	}

	// --data seeds the writers with a fixture's own values before they render, so re-recording an
	// existing file keeps what it was curated with and only adds what the format has since gained.
	// Without it every theme would record whatever this machine happens to look like.
	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)
		}
	}

View on GitHub (pinned to 0976794618)

Solutions

  1. Check the wrapped cause to see which sanitization step failed
  2. Update oh-my-posh — this usually indicates a mismatch between recording and sanitizing logic fixed upstream
  3. Retry recording just that theme with --config + --sanitize to isolate it from the batch
  4. If developing: add/fix the sanitizer rule for the segment named in the wrapped error

Example fix

// before (sanitizer unaware of new segment)
// no case for "newsegment" in sanitizeDataDocument

// after
// add a scrub rule for the newsegment's identity-bearing keys
Defensive patterns

Strategy: try-catch

Try / catch

sanitized, err := sanitizeDataDocument(doc, cfg)
if err != nil {
	if strings.Contains(err.Error(), "failed to sanitize theme") {
		log.Printf("sanitizer rejected theme output: %v", err)
		return err
	}
	return err
}

Prevention

When it happens

Trigger: Running `config export data --themes --sanitize` when sanitizeDataDocument errors on the theme's freshly recorded document — e.g. the document lacks an expected structure the sanitizer assumes, or a scrubber fails on this theme's segment data.

Common situations: A theme recording a segment shape the sanitizer does not expect (new segment type added without a sanitization rule); malformed recorded document from an upstream marshal glitch; custom or dev builds where sanitizer and record formats drifted.

Related errors


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