JanDeDobbeleer/oh-my-posh · error
failed to parse env data: %w
Error message
failed to parse env data: %w
What it means
Thrown by Data.EnvFlags when the env section captured from the data file is not a valid JSON object of environment variable names to values. The stored raw JSON is unmarshaled into a map[string]string-shaped struct; invalid JSON or non-string values fail and are wrapped with this message.
Source
Thrown at src/config/data.go:299
}
return s
default:
return v
}
}
// EnvFlags parses the env section for the properties that route into
// runtime.Flags instead of the template cache. Unknown keys are ignored.
func (d *Data) EnvFlags() (*EnvData, error) {
env := &EnvData{}
if len(d.Env) == 0 {
return env, nil
}
if err := json.Unmarshal(d.Env, env); err != nil {
return nil, fmt.Errorf("failed to parse env data: %w", err)
}
return env, nil
}
// ApplyFlags copies d onto flags: SegmentData/EnvData verbatim, plus the env
// keys that map directly onto runtime.Flags fields (see EnvFlags/EnvData),
// with precedence explicit CLI flag > data file > live environment. changed
// reports whether the corresponding CLI flag (by name) was set explicitly, in
// which case the data file's value is skipped; a nil changed means "never
// overridden," for a caller with no CLI flags of its own to check against
// (prompt/golden_test.go's fixture harness).
func (d *Data) ApplyFlags(flags *runtime.Flags, changed func(name string) bool) error {
if changed == nil {
changed = func(string) bool { return false }
}
flags.SegmentData = d.SegmentsView on GitHub (pinned to 0976794618)
Solutions
- Quote every env value so it is a JSON string: MY_PORT = "8080"
- Make sure env is a table/object, not an array or scalar
- Check the wrapped error after '%w' for which key had the wrong type
- Re-derive Env from the data file rather than hand-crafting raw JSON
Example fix
// before (data.toml) [env] MY_PORT = 8080 DEBUG = true // after [env] MY_PORT = "8080" DEBUG = "true"
Defensive patterns
Strategy: validation
Validate before calling
func envValuesAreStrings(raw []byte) error {
var root map[string]json.RawMessage
if err := json.Unmarshal(raw, &root); err != nil { return err }
env, ok := root["env"]
if !ok { return nil }
var m map[string]string
return json.Unmarshal(env, &m)
}
// rejects non-string env values before EnvFlags ever runs Try / catch
flags, err := data.EnvFlags()
if err != nil {
return fmt.Errorf("env section malformed (all values must be strings): %w", err)
} Prevention
- Quote every env value in data files, even numbers and booleans
- Keep env a flat table of name = "value" pairs
- Never hand-craft the raw Env JSON - load it from the file
- Test EnvFlags/ApplyFlags paths in unit tests with real data files
When it happens
Trigger: Calling EnvFlags (directly or via ApplyFlags) on a Data whose Env was set from a data file where env is not an object, or whose env values are not strings (e.g. env = { FOO = 1 } decodes to a JSON number that cannot unmarshal into a string field).
Common situations: Writing numeric or boolean env values in a TOML/YAML data file (MY_PORT = 8080) instead of quoting them; env defined as a list; corrupted cached env JSON passed through ApplyFlags.
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 version in data file: %w
- failed to parse segments in data file: %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/b22b3a2af9651102.
Report an issue: GitHub.