{"id":"a098f7f1d8d1a21b","repo":"gohugoio/hugo","slug":"failed-to-load-config-w","errorCode":null,"errorMessage":"failed to load config: %w","messagePattern":"failed to load config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/allconfig/load.go","lineNumber":68,"sourceCode":"\t\t}\n\t}()\n\n\tif len(d.Environ) == 0 && !hugo.IsRunningAsTest() {\n\t\td.Environ = os.Environ()\n\t}\n\n\tif d.Logger == nil {\n\t\td.Logger = loggers.NewDefault()\n\t}\n\n\tl := &configLoader{ConfigSourceDescriptor: d, cfg: config.New()}\n\t// Make sure we always do this, even in error situations,\n\t// as we have commands (e.g. \"hugo mod init\") that will\n\t// use a partial configuration to do its job.\n\tdefer l.deleteMergeStrategies()\n\tres, _, err := l.loadConfigMain(d)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load config: %w\", err)\n\t}\n\n\tconfigs, err = fromLoadConfigResult(d.Fs, d.Logger, res)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create config from result: %w\", err)\n\t}\n\n\tmoduleConfig, modulesClient, err := l.loadModules(configs, d.IgnoreModuleDoesNotExist)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load modules: %w\", err)\n\t}\n\n\tif len(l.ModulesConfigFiles) > 0 {\n\t\t// Config merged in from modules.\n\t\t// Re-read the config.\n\t\tconfigs, err = fromLoadConfigResult(d.Fs, d.Logger, res)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create config from modules config: %w\", err)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/config/allconfig/load.go#L50-L86","documentation":"Wrap returned when l.loadConfigMain fails — the phase that locates, parses and merges the main config file(s), config/ directory, environment overrides and theme configs. It wraps the concrete cause (TOML/YAML/JSON parse error, ErrNoConfigFile, an invalid environment override, a failing section decoder) with a generic 'failed to load config' prefix.","triggerScenarios":"Syntax errors in hugo.toml/hugo.yaml/hugo.json or files under config/_default/; duplicate TOML keys; a HUGO_* environment variable that fails to parse into the expected type; a section decoder from alldecoders.go returning an error during the main merge pass; unreadable config files (permissions).","commonSituations":"A stray character or unclosed quote after hand-editing config; mixing tabs/spaces in YAML config; CI setting HUGO_PARAMS_* env vars with malformed values; splitting config into config/_default/*.toml and introducing a duplicate or misnamed file.","solutions":["Read the wrapped inner error — it usually includes the file name and line/column of the parse failure; fix that syntax.","Validate the config file with a TOML/YAML linter matching its extension.","Unset or fix HUGO_* environment variables if the error appears only in one environment (compare `env | grep HUGO`).","If using a config/ directory, check every file in config/_default/ and the active environment directory parses on its own."],"exampleFix":"# before (hugo.toml — unclosed string)\ntitle = \"My Site\nbaseURL = 'https://example.org/'\n# after\ntitle = \"My Site\"\nbaseURL = 'https://example.org/'","handlingStrategy":"try-catch","validationCode":"// If loading from a config dir, verify it exists and is a directory\nfi, err := os.Stat(configDir)\nif err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"config dir %q missing or not a directory\", configDir)\n}","typeGuard":null,"tryCatchPattern":"conf, err := allconfig.LoadConfig(opts)\nif err != nil {\n    var fe herrors.FileError\n    if errors.As(err, &fe) {\n        // file/line available — show it, don't swallow\n    }\n    return err\n}","preventionTips":["Use errors.As with herrors.FileError to extract filename/line for user-facing messages — this one wraps with %w so unwrapping works","Validate environment-specific config dirs (config/production etc.) in CI, not just the default","Fail fast on load error; never proceed with a partially-loaded config"],"tags":["hugo","config","parsing","toml","yaml"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}