{"id":"7c898951b34eb9c6","repo":"gohugoio/hugo","slug":"failed-to-load-config-v","errorCode":null,"errorMessage":"failed to load config: %v","messagePattern":"failed to load config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"config/allconfig/load.go","lineNumber":48,"sourceCode":"\t\"github.com/gohugoio/hugo/common/loggers\"\n\t\"github.com/gohugoio/hugo/common/paths\"\n\t\"github.com/gohugoio/hugo/common/types\"\n\t\"github.com/gohugoio/hugo/config\"\n\t\"github.com/gohugoio/hugo/helpers\"\n\thglob \"github.com/gohugoio/hugo/hugofs/hglob\"\n\t\"github.com/gohugoio/hugo/modules\"\n\t\"github.com/gohugoio/hugo/modules/npm\"\n\t\"github.com/gohugoio/hugo/parser/metadecoders\"\n\t\"github.com/spf13/afero\"\n)\n\n//lint:ignore ST1005 end user message.\nvar ErrNoConfigFile = errors.New(\"Unable to locate config file or config directory. Perhaps you need to create a new project.\\n       Run `hugo help new` for details.\\n\")\n\nfunc LoadConfig(d ConfigSourceDescriptor) (configs *Configs, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"failed to load config: %v\", r)\n\t\t\tdebug.PrintStack()\n\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)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/config/allconfig/load.go#L30-L66","documentation":"Produced by the deferred recover() at the top of LoadConfig: if anything in the config-loading pipeline panics, the panic value is converted into this error (with %v, so no wrapped cause chain) and the stack is printed via debug.PrintStack. It is a catch-all guard so a bug or pathological config crashes with a diagnosable error instead of an unrecovered panic.","triggerScenarios":"Any panic during config loading — a nil-pointer dereference or index-out-of-range in a config decoder, a panicking template/module hook, or config values of unexpected types that a decoder asserts on without checking. The accompanying stack trace on stderr identifies the real site.","commonSituations":"Hitting a Hugo bug with an unusual config shape (a scalar where a map is expected in an obscure section); building with a mismatched or corrupted module cache; regressions in a freshly upgraded Hugo version.","solutions":["Read the printed stack trace — it names the exact decoder/function that panicked; the message alone only says loading failed.","Bisect your config: comment out recently changed sections until the panic disappears to find the offending value.","Upgrade to the latest Hugo release in case the panic is a fixed bug; if it reproduces on latest, report it at github.com/gohugoio/hugo/issues with the stack trace and a minimal config.","Check for type mismatches in config (e.g. a string where a table is expected) in the section the stack trace implicates."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"conf, err := allconfig.LoadConfig(opts)\nif err != nil {\n    var fe herrors.FileError\n    if errors.As(err, &fe) {\n        log.Printf(\"config error at %s: %v\", fe.Position(), err)\n    }\n    return fmt.Errorf(\"hugo config load: %w\", err)\n}","preventionTips":["Note this wrapper uses %v, not %w — don't rely on unwrapping through it; match on the file-error type or message from the inner loader instead","Lint config files (TOML/YAML syntax) in CI before running Hugo","Keep configDir (config/_default, config/production) layouts consistent so merge errors don't surface only in one environment"],"tags":["hugo","config","panic","go"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}