{"record":{"id":"affb45e1de593cf0","repo":"derailed/k9s","slug":"context-config-yaml-load-failed-w-s","errorCode":null,"errorMessage":"context-config yaml load failed: %w\n%s","messagePattern":"context-config yaml load failed: %w\n(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/data/dir.go","lineNumber":98,"sourceCode":"\nfunc (d *Dir) loadConfig(path string) (*Config, error) {\n\td.mx.Lock()\n\tdefer d.mx.Unlock()\n\n\tbb, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err := JSONValidator.Validate(json.ContextSchema, bb); err != nil {\n\t\tslog.Warn(\"Validation failed. Please update your config and restart!\",\n\t\t\tslogs.Path, path,\n\t\t\tslogs.Error, err,\n\t\t)\n\t}\n\n\tvar cfg Config\n\tif err := yaml.Unmarshal(bb, &cfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"context-config yaml load failed: %w\\n%s\", err, string(bb))\n\t}\n\n\treturn &cfg, nil\n}\n","sourceCodeStart":80,"sourceCodeEnd":103,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/config/data/dir.go#L80-L103","documentation":"Returned by the per-context config loader in internal/config/data/dir.go:98 when yaml.Unmarshal of a context-specific config file (under K9S_CONFIG_DIR/contexts/<cluster>/<context>.yaml) fails. The error deliberately embeds the full file content (%s) after the cause so the broken YAML is visible in logs. Schema violations only log a warning; a true unmarshal failure returns this error and aborts loading that context's config.","triggerScenarios":"Hand-editing a context yaml and breaking structure (tabs, wrong types like namespace.active: 3 when a string is expected); a context config written by a newer k9s then opened by an older one; templating tools mangling the file.","commonSituations":"Customizing per-context preferences (namespace favorites, view settings); downgrading k9s versions; dotfile sync across versions; partial writes on disk-full.","solutions":["Read the error output — it contains both the parse cause and the entire file content; fix the flagged structure","Run yamllint on the exact path shown to get line/column","If the file is expendable, delete it — k9s regenerates sane defaults on next activation","Pin one k9s version on machines sharing the config directory"],"exampleFix":"# before: contexts/prod-c/prod.yaml\ncontext:\n  namespace:\n\tactive: default   # TAB indentation -> unmarshal error\n\n# after (spaces only)\ncontext:\n  namespace:\n    active: default","handlingStrategy":"try-catch","validationCode":"func contextYamlParses(path string) error {\n\tbb, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar probe data.Config\n\treturn yaml.Unmarshal(bb, &probe)\n}","typeGuard":null,"tryCatchPattern":"if _, err := k9s.ActivateContext(name); err != nil {\n\tif strings.Contains(err.Error(), \"context-config yaml load failed\") {\n\t\t// the error embeds the full file content — log it,\n\t\t// then remove the file so defaults regenerate on next activation\n\t}\n}","preventionTips":["Use spaces only when editing files under contexts/; tabs break YAML unmarshal","Keep per-context edits minimal — copy the documented shape exactly","Version the k9s config dir in git so a bad edit is one revert away"],"tags":["k9s","yaml","parsing","context-config","unmarshal"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}