{"record":{"id":"35d32a6811202e47","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-parse-segments-for-theme-s-w","errorCode":null,"errorMessage":"failed to parse segments for theme %s: %w","messagePattern":"failed to parse segments for theme (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/config_export_data.go","lineNumber":249,"sourceCode":"\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.\nfunc countPopulatedLeaves(raw json.RawMessage) int {\n\tvar v any\n\tif err := json.Unmarshal(raw, &v); err != nil {\n\t\treturn 0\n\t}\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/config_export_data.go#L231-L267","documentation":"This error is thrown by recordThemeSanitized when the `segments` key (config.DataSegmentsKey) of a recorded theme cannot be unmarshalled into the segments structure. The document and env parsed, but the segments payload has an unexpected JSON shape. The underlying unmarshal error is wrapped with the theme path.","triggerScenarios":"Running `oh-my-posh config export data --themes <dir> --sanitize` where a theme's recorded `segments` entry is not the expected object/array shape (e.g. segments is a scalar, or segment entries have fields of the wrong type).","commonSituations":"A hand-merged or hand-edited fixture where segments were combined incorrectly; fixtures recorded by an older oh-my-posh whose segment structs changed (renamed or retyped properties); a merge script that overwrote the segments key with the wrong type.","solutions":["Inspect the `segments` key in the theme file named in the error and restore the expected shape (objects per segment with correctly typed properties)","Regenerate the merged fixture with `oh-my-posh config export data --themes <dir> --sanitize` rather than merging files manually","Read the wrapped %w error to find the exact segment property with the wrong type and fix it","If segment structs changed between versions, re-record all fixtures with the current binary"],"exampleFix":"// before: segments as a string\n{ \"segments\": \"text\" }\n// after\n{ \"segments\": { \"git\": { \"text\": \"main\" } } }","handlingStrategy":"validation","validationCode":"var root map[string]json.RawMessage\nif err := json.Unmarshal(raw, &root); err != nil { return err }\nsegRaw, ok := root[\"segments\"]\nif ok {\n    var segments map[string]any\n    if err := json.Unmarshal(segRaw, &segments); err != nil {\n        return fmt.Errorf(\"segments key must be an object: %w\", err)\n    }\n}","typeGuard":"func hasWellFormedSegments(doc []byte) bool {\n    var root struct { Segments map[string]json.RawMessage `json:\"segments\"` }\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: segment field %s wrong type (want %s)\", themePath, uerr.Field, uerr.Type)\n    }\n    return err\n}","preventionTips":["Regenerate merged fixtures with the official --themes --sanitize command instead of ad-hoc merge scripts","Re-record all fixtures after upgrading oh-my-posh segment structs","Keep a JSON schema for data fixtures and lint them in CI"],"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"}