{"record":{"id":"1ebba26d60aad011","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-parse-segments-in-data-file-w","errorCode":null,"errorMessage":"failed to parse segments in data file: %w","messagePattern":"failed to parse segments in data file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/data.go","lineNumber":232,"sourceCode":"// once each has the same map[string]json.RawMessage shape in hand.\nfunc dataFromRoot(root map[string]json.RawMessage) (*Data, error) {\n\tdata := &Data{}\n\n\tif versionRaw, OK := root[DataVersionKey]; OK {\n\t\tif err := json.Unmarshal(versionRaw, &data.Version); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse version in data file: %w\", err)\n\t\t}\n\t}\n\n\tif env, OK := root[DataEnvKey]; OK {\n\t\tdata.Env = env\n\t}\n\n\tif segmentsRaw, OK := root[DataSegmentsKey]; OK {\n\t\tvar segments map[string]json.RawMessage\n\n\t\tif err := json.Unmarshal(segmentsRaw, &segments); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse segments in data file: %w\", err)\n\t\t}\n\n\t\tdata.Segments = segments\n\t}\n\n\treturn data, nil\n}\n\n// normalize re-marshals a generically decoded section (as produced by the\n// YAML/TOML unmarshalers) to a map of raw JSON so the rest of the pipeline\n// can treat all formats uniformly.\nfunc normalize(generic map[string]any) (map[string]json.RawMessage, error) {\n\troot := make(map[string]json.RawMessage, len(generic))\n\n\tfor key, value := range generic {\n\t\tb, err := json.Marshal(sanitize(value))\n\t\tif err != nil {\n\t\t\treturn nil, err","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/config/data.go#L214-L250","documentation":"Thrown by dataFromRoot when the 'segments' key is present in a data file but is not a JSON object (map of string keys to values). The raw JSON for segments is unmarshaled into map[string]json.RawMessage; an array, string, number, or null fails and is wrapped with this message.","triggerScenarios":"Calling LoadData or ParseData where the segments key holds a non-object: segments = [] in TOML, segments: - a in YAML (a list), or segments: \"text\"; note null also fails since it cannot unmarshal into map[string]json.RawMessage.","commonSituations":"Mistakenly defining segments as a list (as in the main theme config where segments is an array) instead of a keyed map; a merge/format-conversion tool reshaping segments; hand-written YAML indentation producing a list.","solutions":["Change segments to a keyed object: [segments] in TOML or segments: { key: {...} } in YAML","Remove the segments key if no per-segment data is needed","Cross-check against the main config format - theme segments arrays and data-file segment maps are different shapes"],"exampleFix":"// before (data.yaml)\nsegments:\n  - os\n  - path\n// after\nsegments:\n  os:\n    template: \"{{ .Icon }} \"","handlingStrategy":"validation","validationCode":"func segmentsIsObject(raw []byte) error {\n\tvar root map[string]json.RawMessage\n\tif err := json.Unmarshal(raw, &root); err != nil { return err }\n\tif v, ok := root[\"segments\"]; ok {\n\t\tvar m map[string]json.RawMessage\n\t\treturn json.Unmarshal(v, &m)\n\t}\n\treturn nil\n}","typeGuard":"func segmentsIsObject(root map[string]json.RawMessage) bool {\n\tvar m map[string]json.RawMessage\n\tv, ok := root[\"segments\"]\n\treturn ok && json.Unmarshal(v, &m) == nil && m != nil\n}","tryCatchPattern":"data, err := config.LoadData(path)\nif err != nil && strings.Contains(err.Error(), \"failed to parse segments\") {\n\treturn fmt.Errorf(\"segments must be a keyed object, not a list: %w\", err)\n}","preventionTips":["Remember: data-file segments is a map, theme segments is an array","Never set segments to null - omit the key instead","Verify YAML indentation so segments stays a mapping, not a list","Validate data files against an expected schema"],"tags":["json","config","segments"],"backgroundTag":"segments-parse-failed","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}