{"record":{"id":"cdb16dfb93c07ebc","repo":"derailed/k9s","slug":"main-config-yaml-load-failed-w","errorCode":null,"errorMessage":"main config.yaml load failed: %w","messagePattern":"main config\\.yaml load failed: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/config.go","lineNumber":288,"sourceCode":"// Load loads K9s configuration from file.\nfunc (c *Config) Load(path string, force bool) error {\n\tif _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {\n\t\tif err := c.Save(force); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tbb, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar errs error\n\tif err := data.JSONValidator.Validate(json.K9sSchema, bb); err != nil {\n\t\terrs = errors.Join(errs, fmt.Errorf(\"k9s config file %q load failed:\\n%w\", path, err))\n\t}\n\n\tvar cfg Config\n\tif err := yaml.Unmarshal(bb, &cfg); err != nil {\n\t\terrs = errors.Join(errs, fmt.Errorf(\"main config.yaml load failed: %w\", err))\n\t}\n\tc.Merge(&cfg)\n\n\treturn errs\n}\n\n// Save configuration to disk.\nfunc (c *Config) Save(force bool) error {\n\tcontextName := c.K9s.ActiveContextName()\n\t// Skip saving if no context is configured\n\tif contextName == \"\" {\n\t\tslog.Debug(\"No context configured, skipping config save\")\n\t\treturn nil\n\t}\n\tclusterName, err := c.ActiveClusterName(contextName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to locate associated cluster for context %q: %w\", contextName, err)\n\t}","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/config/config.go#L270-L306","documentation":"Returned from Config.Load (internal/config/config.go:288) when yaml.Unmarshal of the main config file into a Config struct fails. Unlike the schema check (which only warns into the joined error), a structural unmarshal failure means the file cannot be mapped onto the config types: wrong value types (string where int expected), duplicate keys, or malformed YAML. Joined with other errors and returned after the Merge of the zero-value/previous config.","triggerScenarios":"Hand-editing config.yml and introducing a tab character, wrong indentation level, or a scalar of the wrong type (e.g. refreshRate: fast instead of an integer); YAML aliases/anchors the decoder rejects; file truncated mid-write.","commonSituations":"Manual edits late at night; editor inserting tabs; syncing dotfiles that got mangled by templating; disk-full partial writes.","solutions":["Run yamllint (or python -c 'import yaml,sys; yaml.safe_load(open(\"config.yml\"))') to get the exact line/column","Fix the reported structural problem — usually indentation or type","Restore from backup or delete the file so k9s regenerates defaults, then re-apply changes incrementally"],"exampleFix":"# before\nk9s:\n    refreshRate: fast\n    headless: 2\n\n# after\nk9s:\n  refreshRate: 2\n  headless: false","handlingStrategy":"try-catch","validationCode":"func configParses(path string) error {\n\tbb, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar probe map[string]any\n\tif err := yaml.Unmarshal(bb, &probe); err != nil {\n\t\treturn fmt.Errorf(\"config.yml invalid YAML: %w\", err)\n\t}\n\treturn nil\n}","typeGuard":"func isYamlTypeError(err error) bool {\n\tvar te *yaml.TypeError\n\treturn errors.As(err, &te)\n}","tryCatchPattern":"if err := cfg.Load(path, false); err != nil {\n\tvar te *yaml.TypeError\n\tif errors.As(err, &te) {\n\t\tfor _, msg := range te.Errors {\n\t\t\tlog.Printf(\"config type error: %s\", msg) // line + expected type\n\t\t}\n\t\t// offer to regenerate the file from defaults\n\t}\n}","preventionTips":["Use spaces (never tabs) and a fixed 2-space indent in k9s yaml configs","Run yamllint on config.yml inside your dotfiles CI","Check scalar types against the docs: booleans as true/false, numbers unquoted"],"tags":["k9s","config","yaml","parsing","unmarshal"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}