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 the

View on GitHub (pinned to 0976794618)

Solutions

  1. Verify the file exists at the exact path (ls -la <path>)
  2. Use an absolute path or correct the relative path relative to the current working directory
  3. Fix permissions on the file so the running user can read it
  4. 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

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


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/4ab19598aba426a7. Report an issue: GitHub.