JanDeDobbeleer/oh-my-posh · error
failed to parse data file: %w
Error message
failed to parse data file: %w
What it means
After reading the data file, decodeDataRoot unmarshals content based on file extension. For .json/.jsonc files, JSON comments are stripped and json.Unmarshal runs; on failure this wrapped error is returned. The file was readable but its contents are not valid JSON (or JSONC after comment stripping).
Source
Thrown at src/config/data.go:177
if err != nil {
return nil, err
}
return dataFromRoot(root)
}
// decodeDataRoot decodes raw into a generic map of raw JSON messages,
// dispatching on ext exactly as LoadData's own format switch used to do
// inline, before ParseData needed the same switch for its one fixed format.
func decodeDataRoot(ext string, raw []byte) (map[string]json.RawMessage, error) {
var root map[string]json.RawMessage
switch ext {
case JSON, JSONC:
raw = []byte(text.StripJSONComments(string(raw)))
if err := json.Unmarshal(raw, &root); err != nil {
return nil, fmt.Errorf("failed to parse data file: %w", err)
}
case YAML, YML:
var generic map[string]any
if err := yaml.Unmarshal(raw, &generic); err != nil {
return nil, fmt.Errorf("failed to parse data file: %w", err)
}
normalized, err := normalize(generic)
if err != nil {
return nil, fmt.Errorf("failed to parse data file: %w", err)
}
root = normalized
case TOML, TML:
var generic map[string]any
if err := toml.Unmarshal(raw, &generic); err != nil {View on GitHub (pinned to 0976794618)
Solutions
- Run the file through a JSON linter/parser to locate the syntax error
- Remove trailing commas and ensure keys/strings are double-quoted
- Remove leftover git merge-conflict markers
- Confirm the file extension matches the actual content format (rename to .yaml if it is YAML)
Example fix
// before (data.json)
{ "version": 1, }
// after
{ "version": 1 } Defensive patterns
Strategy: validation
Validate before calling
var probe any
if err := json.Unmarshal(raw, &probe); err != nil {
return fmt.Errorf("invalid JSON in %s: %w", path, err)
} Type guard
func isValidJSON(raw []byte) bool { var v any; return json.Unmarshal(raw, &v) == nil } Try / catch
data, err := config.LoadData(path)
if err != nil && strings.Contains(err.Error(), "failed to parse data file") {
log.Fatalf("malformed JSON in %s: %v", path, errors.Unwrap(err))
} Prevention
- Run a JSON linter after hand edits
- Remove merge-conflict markers before saving
- Keep comments in .jsonc files only, plain JSON in .json
- Match file extension to actual content format
When it happens
Trigger: Loading a .json/.jsonc data file containing a syntax error: trailing comma, unquoted key, stray comment not recognized, truncated file, or BOM/encoding issues.
Common situations: Hand-edited theme/data configs left malformed, a merge conflict marker (<<<<<<<) left in the file, copying YAML content into a .json file, or a tool writing partial output on crash.
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
- unclosed section:
- key-value delimiter not found:
- failed to parse theme %s
- failed to parse recorded theme %s: %w
- failed to parse env for theme %s: %w
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/2a88ff0e865c1d91.
Report an issue: GitHub.