{"record":{"id":"4ab19598aba426a7","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-read-data-file-w","errorCode":null,"errorMessage":"failed to read data file: %w","messagePattern":"failed to read data file: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/data.go","lineNumber":136,"sourceCode":"}\n\n// EnvData holds the subset of the env section that maps directly onto\n// runtime.Flags rather than the template cache. Pointer fields let callers\n// detect whether a key was present in the data file.\ntype EnvData struct {\n\tPWD           *string\n\tCode          *int\n\tExecutionTime *float64\n\tPipeStatus    *string\n\tInterrupted   *bool\n\tExecuted      *bool\n}\n\n// The format is derived from the file extension: .json/.jsonc, .yaml/.yml, or .toml.\nfunc LoadData(path string) (*Data, error) {\n\traw, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read data file: %w\", err)\n\t}\n\n\text := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), \".\")\n\n\troot, err := decodeDataRoot(ext, raw)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn dataFromRoot(root)\n}\n\n// ParseData decodes a data document already in memory as JSON - the one\n// format a caller with no file path can name unambiguously (the js/wasm\n// entrypoint's dataJSON argument is exactly this: the studio hands over the\n// text of a file it already read on its own side, with no extension to\n// derive a format from). LoadData's YAML/TOML branches stay file-only; they\n// exist for a --data flag pointing at a hand-written file, not for the","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/config/data.go#L118-L154","documentation":"LoadData reads a config/data file from disk before decoding it by extension. If os.ReadFile fails, this wrapped error is returned. It means the file could not be opened — most commonly it does not exist at the given path.","triggerScenarios":"Calling LoadData (directly or via applyDataFile / CLI --config/--data flags) with a path to a missing file, a directory instead of a file, or a file the process cannot read.","commonSituations":"Typo in the config path, referencing ~/.poshthemes/... that was never created, switching machines without copying the config, or CI where the config file isn't checked out.","solutions":["Verify the file exists at the exact path (ls -la <path>)","Use an absolute path or correct the relative path relative to the current working directory","Fix permissions on the file so the running user can read it","Ensure the path points to a file, not a directory"],"exampleFix":"// before\nloadData(\"~/.config/oh-my-posh/themes.omp.jsnon\")\n// after\nloadData(\"~/.config/oh-my-posh/themes.omp.json\")","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {\n    return fmt.Errorf(\"data file not found: %s\", path)\n}","typeGuard":"func fileExists(p string) bool { info, err := os.Stat(p); return err == nil && !info.IsDir() }","tryCatchPattern":"data, err := config.LoadData(path)\nif err != nil && strings.Contains(err.Error(), \"failed to read data file\") {\n    log.Fatalf(\"cannot open %s: %v\", path, errors.Unwrap(err))\n}","preventionTips":["Use absolute paths or resolve from $HOME","Verify file exists after machine/CI migration","Ensure the path points to a file, not a directory","Check read permissions for the running user"],"tags":["filesystem","io","config"],"backgroundTag":"file-not-found","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}