{"record":{"id":"b15937bb3dc18b8c","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-parse-env-for-theme-s-w","errorCode":null,"errorMessage":"failed to parse env for theme %s: %w","messagePattern":"failed to parse env for theme (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/config_export_data.go","lineNumber":243,"sourceCode":"\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\n// non-empty string, a non-zero number, true, or a non-empty array/map each\n// count as 1; a leaf holding the zero value for its type (including null)\n// counts as 0. Containers themselves are not counted, only what they hold -\n// an empty array contributes 0, a 3-element array contributes the sum of\n// its elements' own counts.","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/config_export_data.go#L225-L261","documentation":"This error is thrown by recordThemeSanitized when the `env` key (config.DataEnvKey) inside a recorded/sanitized theme document cannot be unmarshalled into the env structure. The theme parsed fine at the top level, but the value under the env key is not the expected JSON shape. It wraps the underlying unmarshal error with the theme path.","triggerScenarios":"Running `oh-my-posh config export data --themes <dir> --sanitize` where a theme's recorded `env` entry is not an object matching the env schema (e.g. env is a string, array, or contains fields of the wrong type).","commonSituations":"A data fixture was edited by hand and the env block's structure was changed; a fixture generated by an older oh-my-posh version has an env layout that no longer matches current struct fields (e.g. a field changed from string to number).","solutions":["Open the theme/data file named in the message and inspect the `env` key: it must be a JSON object with correctly typed fields","Regenerate the fixture with `oh-my-posh config export data --themes <dir> --sanitize` from a clean checkout instead of hand-editing it","If a schema migration changed env field types, delete the stale fixture and re-record it with the current binary","Check the underlying %w error for the exact JSON field/type mismatch and correct that field"],"exampleFix":"// before: env with wrong type\n{ \"env\": [\"SHELL=bash\"] }\n// after\n{ \"env\": { \"SHELL\": \"bash\" } }","handlingStrategy":"validation","validationCode":"var root map[string]json.RawMessage\nif err := json.Unmarshal(raw, &root); err != nil { return err }\nenvRaw, ok := root[\"env\"]\nif ok {\n    var env map[string]any\n    if err := json.Unmarshal(envRaw, &env); err != nil {\n        return fmt.Errorf(\"env key must be an object: %w\", err)\n    }\n}","typeGuard":"func hasWellFormedEnv(doc []byte) bool {\n    var root struct { Env map[string]json.RawMessage `json:\"env\"` }\n    return json.Unmarshal(doc, &root) == nil\n}","tryCatchPattern":"env, segments, err := recordThemeSanitized(themePath)\nif err != nil {\n    var uerr *json.UnmarshalTypeError\n    if errors.As(err, &uerr) {\n        log.Fatalf(\"theme %s: field %s has wrong type (want %s): %v\", themePath, uerr.Field, uerr.Type, uerr)\n    }\n    return err\n}","preventionTips":["Do not hand-edit recorded data fixtures; always regenerate with config export data","When merging fixtures, merge per-key with identical shapes rather than concatenating JSON","Diff regenerated fixtures against committed ones in CI to catch schema drift early"],"tags":["json","parsing","cli","fixture"],"backgroundTag":"invalid-json","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}