{"id":"4bbb04f07cc8de10","repo":"gohugoio/hugo","slug":"failed-to-unmarshal-config-for-path-q-w","errorCode":null,"errorMessage":"failed to unmarshal config for path %q: %w","messagePattern":"failed to unmarshal config for path %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/configLoader.go","lineNumber":172,"sourceCode":"\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\tif fi.IsDir() {\n\t\t\t\tdirnames = append(dirnames, path)\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\tif !IsValidConfigFilename(path) {\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\tname := paths.Filename(filepath.Base(path))\n\n\t\t\titem, err := metadecoders.Default.UnmarshalFileToMap(sourceFs, path)\n\t\t\tif err != nil {\n\t\t\t\t// This will be used in error reporting, use the most specific value.\n\t\t\t\tdirnames = []string{path}\n\t\t\t\treturn fmt.Errorf(\"failed to unmarshal config for path %q: %w\", path, err)\n\t\t\t}\n\n\t\t\tvar keyPath []string\n\t\t\tvar unwrapKey string\n\t\t\tif !DefaultConfigNamesSet[name] {\n\t\t\t\t// Can be params.jp, menus.en etc.\n\t\t\t\tname, lang := paths.FileAndExtNoDelimiter(name)\n\t\t\t\tunwrapKey = name\n\n\t\t\t\tkeyPath = []string{name}\n\n\t\t\t\tif lang != \"\" {\n\t\t\t\t\tkeyPath = []string{\"languages\", lang}\n\t\t\t\t\tswitch name {\n\t\t\t\t\tcase \"menu\", \"menus\":\n\t\t\t\t\t\tkeyPath = append(keyPath, \"menus\")\n\t\t\t\t\tcase \"params\":\n\t\t\t\t\t\tkeyPath = append(keyPath, \"params\")","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/config/configLoader.go#L154-L190","documentation":"Raised while loading the split config directory (`config/_default`, `config/production`, etc.): a config file found during the walk failed to parse via metadecoders.UnmarshalFileToMap. The error wraps the underlying TOML/YAML/JSON syntax error and pins error reporting to the exact file path.","triggerScenarios":"Any file with a valid config filename/extension under a config dir containing malformed content — TOML with unbalanced brackets or duplicate keys, YAML with bad indentation or tabs, JSON with trailing commas — encountered by `hugo`, `hugo server`, or `hugo config` when merging the config directory.","commonSituations":"Merge-conflict markers (`<<<<<<<`) left in a config file; editing `config/_default/params.toml` with YAML syntax (or vice versa) so the extension doesn't match the content; smart quotes pasted from docs; stray non-config text files saved with a `.toml`/`.yaml` extension in the config tree.","solutions":["Open the file at the quoted path and fix the syntax error described in the wrapped message (it includes line/position for TOML/YAML).","Ensure the file's content matches its extension — TOML in `.toml`, YAML in `.yaml`.","Check for leftover git conflict markers or editor artifacts; validate the file with a TOML/YAML linter.","Move non-config files out of the config directory."],"exampleFix":"# before (config/_default/params.toml)\n[social\ntwitter = \"user\"\n\n# after\n[social]\ntwitter = \"user\"","handlingStrategy":"try-catch","validationCode":"// Pre-check that the value at the path is a table/map before decoding into a struct\nv := cfg.Get(\"outputFormats\")\nif v != nil {\n    if _, ok := v.(maps.Params); !ok {\n        return fmt.Errorf(\"config key %q must be a table, got %T\", \"outputFormats\", v)\n    }\n}","typeGuard":"func asParams(v any) (maps.Params, bool) {\n    p, ok := v.(maps.Params)\n    return p, ok\n}","tryCatchPattern":"conf, err := allconfig.LoadConfig(configs.ConfigSourceDescriptor{...})\nif err != nil {\n    // \"failed to unmarshal config for path %q\" names the offending top-level key —\n    // its TOML/YAML shape (scalar vs table vs array) doesn't match the expected schema\n    return fmt.Errorf(\"load config: %w\", err)\n}","preventionTips":["The %q path in the error names the config section whose shape is wrong — check whether it should be a table ([section]) vs array of tables ([[section]]) vs scalar","YAML indentation errors commonly turn a map into a string; lint config files (yamllint/taplo) in CI","When upgrading Hugo, diff the release notes for config schema changes before assuming your old file still unmarshals"],"tags":["hugo","config","parsing","toml","yaml"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}