JanDeDobbeleer/oh-my-posh · error
failed to read data file: %w
Error message
failed to read data file: %w
What it means
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.
Source
Thrown at src/config/data.go:136
}
// EnvData holds the subset of the env section that maps directly onto
// runtime.Flags rather than the template cache. Pointer fields let callers
// detect whether a key was present in the data file.
type EnvData struct {
PWD *string
Code *int
ExecutionTime *float64
PipeStatus *string
Interrupted *bool
Executed *bool
}
// The format is derived from the file extension: .json/.jsonc, .yaml/.yml, or .toml.
func LoadData(path string) (*Data, error) {
raw, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read data file: %w", err)
}
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
root, err := decodeDataRoot(ext, raw)
if err != nil {
return nil, err
}
return dataFromRoot(root)
}
// ParseData decodes a data document already in memory as JSON - the one
// format a caller with no file path can name unambiguously (the js/wasm
// entrypoint's dataJSON argument is exactly this: the studio hands over the
// text of a file it already read on its own side, with no extension to
// derive a format from). LoadData's YAML/TOML branches stay file-only; they
// exist for a --data flag pointing at a hand-written file, not for theView on GitHub (pinned to 0976794618)
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
Example fix
// before
loadData("~/.config/oh-my-posh/themes.omp.jsnon")
// after
loadData("~/.config/oh-my-posh/themes.omp.json") Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("data file not found: %s", path)
} Type guard
func fileExists(p string) bool { info, err := os.Stat(p); return err == nil && !info.IsDir() } Try / catch
data, err := config.LoadData(path)
if err != nil && strings.Contains(err.Error(), "failed to read data file") {
log.Fatalf("cannot open %s: %v", path, errors.Unwrap(err))
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- failed to create directory %s: %w
- failed to write configuration file %s: %w
- failed to read themes directory %s: %w
- invalid export format
- unable to delete font file after registry key open error
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/4ab19598aba426a7.
Report an issue: GitHub.