JanDeDobbeleer/oh-my-posh · error
failed to parse version in data file: %w
Error message
failed to parse version in data file: %w
What it means
Thrown by dataFromRoot when the optional top-level 'version' key exists in a data file but its value is not a valid JSON string. The version field is decoded with json.Unmarshal into data.Version; anything that is not a JSON string (number, object, array, or malformed value) fails and is wrapped with this message.
Source
Thrown at src/config/data.go:220
}
root = normalized
default:
return nil, fmt.Errorf("unsupported data file extension: %s", ext)
}
return root, nil
}
// dataFromRoot builds a Data from a generically-decoded document root,
// shared by LoadData (any of its three formats) and ParseData (JSON only)
// once each has the same map[string]json.RawMessage shape in hand.
func dataFromRoot(root map[string]json.RawMessage) (*Data, error) {
data := &Data{}
if versionRaw, OK := root[DataVersionKey]; OK {
if err := json.Unmarshal(versionRaw, &data.Version); err != nil {
return nil, fmt.Errorf("failed to parse version in data file: %w", err)
}
}
if env, OK := root[DataEnvKey]; OK {
data.Env = env
}
if segmentsRaw, OK := root[DataSegmentsKey]; OK {
var segments map[string]json.RawMessage
if err := json.Unmarshal(segmentsRaw, &segments); err != nil {
return nil, fmt.Errorf("failed to parse segments in data file: %w", err)
}
data.Segments = segments
}
return data, nilView on GitHub (pinned to 0976794618)
Solutions
- Make the version value a quoted string: version = "2" (TOML) or version: "2" (YAML)
- Remove the version key entirely if versioning is not needed
- Re-check the file after converting between formats - conversion tools often turn quoted strings into bare numbers
Example fix
// before (data.toml) version = 2 // after version = "2"
Defensive patterns
Strategy: validation
Validate before calling
func versionIsString(raw []byte) error {
var root map[string]json.RawMessage
if err := json.Unmarshal(raw, &root); err != nil { return err }
if v, ok := root["version"]; ok {
var s string
return json.Unmarshal(v, &s)
}
return nil
} Type guard
func versionIsString(root map[string]json.RawMessage) bool {
var s string
v, ok := root["version"]
return ok && json.Unmarshal(v, &s) == nil
} Try / catch
data, err := config.LoadData(path)
if err != nil && strings.Contains(err.Error(), "failed to parse version") {
// reject or auto-correct the data file before retrying
} Prevention
- Always write version as a quoted string
- Re-check files after running format converters (they unquote strings)
- Omit the version key when not needed
- Schema-validate data files in CI
When it happens
Trigger: Calling LoadData or ParseData on a data file containing a version key whose value is not a JSON string - e.g. version = 1 in TOML/YAML (decodes to a number), version: [1,2] in YAML, or version = true.
Common situations: Author assuming version is numeric and writing version = 2 in a TOML data file; quoting mistakes leaving the value as a number after format conversion; copy-pasting a schema-version integer from another tool.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse data file: %w
- failed to parse segments in data file: %w
- failed to parse env data: %w
- failed to parse data: %w
- invalid export format
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/d65dabc4850a4e3e.
Report an issue: GitHub.