{"record":{"id":"339c8e41d58aedb6","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-parse-recorded-theme-s-w","errorCode":null,"errorMessage":"failed to parse recorded theme %s: %w","messagePattern":"failed to parse recorded theme (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/config_export_data.go","lineNumber":238,"sourceCode":"\tif _, err := render.Config(cfg, 120, true, func(flags *runtime.Flags) error {\n\t\treturn applyDataFile(flags, func(string) bool { return false })\n\t}); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to record theme %s: %w\", themePath, err)\n\t}\n\n\tdoc, err := buildDataDocument(cfg)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to record theme %s: %w\", themePath, err)\n\t}\n\n\tsanitized, err := sanitizeDataDocument(doc, cfg)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to sanitize theme %s: %w\", themePath, err)\n\t}\n\n\tvar root map[string]json.RawMessage\n\tif err := json.Unmarshal(sanitized, &root); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to parse recorded theme %s: %w\", themePath, err)\n\t}\n\n\tif raw, ok := root[config.DataEnvKey]; ok {\n\t\tif err := json.Unmarshal(raw, &env); err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"failed to parse env for theme %s: %w\", themePath, err)\n\t\t}\n\t}\n\n\tif raw, ok := root[config.DataSegmentsKey]; ok {\n\t\tif err := json.Unmarshal(raw, &segments); err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"failed to parse segments for theme %s: %w\", themePath, err)\n\t\t}\n\t}\n\n\treturn env, segments, nil\n}\n\n// countPopulatedLeaves parses raw and counts its non-zero-value leaves: a","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/config_export_data.go#L220-L256","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Run `oh-my-posh config validate --config <themePath>` on the theme named in the message and fix the JSON syntax error it reports","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","Re-download the theme from the official themes directory instead of editing a possibly corrupted copy","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"],"exampleFix":"// before: theme file with trailing comma\n{ \"blocks\": [ { \"type\": \"prompt\", }, ], }\n// after\n{ \"blocks\": [ { \"type\": \"prompt\" } ] }","handlingStrategy":"validation","validationCode":"path := \"themes/mytheme.omp.json\"\nraw, err := os.ReadFile(path)\nif err != nil { return err }\nvar v any\nif err := json.Unmarshal(raw, &v); err != nil {\n    return fmt.Errorf(\"%s is not valid JSON: %w\", path, err)\n}\nif _, ok := v.(map[string]any); !ok {\n    return fmt.Errorf(\"%s: top level must be a JSON object\", path)\n}","typeGuard":"func isValidJSONObject(b []byte) bool {\n    var m map[string]json.RawMessage\n    return json.Unmarshal(b, &m) == nil\n}","tryCatchPattern":"doc, err := recordThemeSanitized(themePath)\nif err != nil {\n    var perr *json.SyntaxError\n    if errors.As(err, &perr) {\n        log.Fatalf(\"theme %s: JSON syntax error at offset %d: %v\", themePath, perr.Offset, perr)\n    }\n    return err\n}","preventionTips":["Validate every theme with `oh-my-posh config validate` before adding it to the themes directory","Run a JSON linter in CI over all files passed to --themes","Never hand-edit exported data fixtures; regenerate them with the export command","Keep theme files from a single trusted source to avoid corrupted copies"],"tags":["json","parsing","cli","theme"],"backgroundTag":"invalid-json","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}