{"record":{"id":"b22b3a2af9651102","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-parse-env-data-w","errorCode":null,"errorMessage":"failed to parse env data: %w","messagePattern":"failed to parse env data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/config/data.go","lineNumber":299,"sourceCode":"\t\t}\n\n\t\treturn s\n\tdefault:\n\t\treturn v\n\t}\n}\n\n// EnvFlags parses the env section for the properties that route into\n// runtime.Flags instead of the template cache. Unknown keys are ignored.\nfunc (d *Data) EnvFlags() (*EnvData, error) {\n\tenv := &EnvData{}\n\n\tif len(d.Env) == 0 {\n\t\treturn env, nil\n\t}\n\n\tif err := json.Unmarshal(d.Env, env); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse env data: %w\", err)\n\t}\n\n\treturn env, nil\n}\n\n// ApplyFlags copies d onto flags: SegmentData/EnvData verbatim, plus the env\n// keys that map directly onto runtime.Flags fields (see EnvFlags/EnvData),\n// with precedence explicit CLI flag > data file > live environment. changed\n// reports whether the corresponding CLI flag (by name) was set explicitly, in\n// which case the data file's value is skipped; a nil changed means \"never\n// overridden,\" for a caller with no CLI flags of its own to check against\n// (prompt/golden_test.go's fixture harness).\nfunc (d *Data) ApplyFlags(flags *runtime.Flags, changed func(name string) bool) error {\n\tif changed == nil {\n\t\tchanged = func(string) bool { return false }\n\t}\n\n\tflags.SegmentData = d.Segments","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/config/data.go#L281-L317","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before (data.toml)\n[env]\nMY_PORT = 8080\nDEBUG = true\n// after\n[env]\nMY_PORT = \"8080\"\nDEBUG = \"true\"","handlingStrategy":"validation","validationCode":"func envValuesAreStrings(raw []byte) error {\n\tvar root map[string]json.RawMessage\n\tif err := json.Unmarshal(raw, &root); err != nil { return err }\n\tenv, ok := root[\"env\"]\n\tif !ok { return nil }\n\tvar m map[string]string\n\treturn json.Unmarshal(env, &m)\n}\n// rejects non-string env values before EnvFlags ever runs","typeGuard":null,"tryCatchPattern":"flags, err := data.EnvFlags()\nif err != nil {\n\treturn fmt.Errorf(\"env section malformed (all values must be strings): %w\", err)\n}","preventionTips":["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"],"tags":["json","env","config"],"backgroundTag":"env-data-parse-failed","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}