{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/config/allconfig/load.go#L30-L66","documentation":"The panic-recovery guard at the top of LoadConfig. A deferred recover() catches any panic during the entire config-loading pipeline and converts it into an error using %v (note: not %w, so the original panic value is stringified, not unwrappable). It also prints the stack trace via debug.PrintStack. This is the catch-all that prevents a raw panic from crashing the process.","triggerScenarios":"A nil-pointer dereference or index-out-of-range inside any decoder or helper during config load; an internal assertion failure (e.g. the `panic(fmt.Sprintf(\"unknown type in languages config: %T\", v))` in allconfig.go:1161); a bug in a third-party module hook executed during load.","commonSituations":"Hitting an internal Hugo bug on an edge-case config; a module/theme whose config triggers an unhandled code path; feeding config values of unexpected Go types (e.g. via mapstructure quirks).","solutions":["Read the printed stack trace to find the panicking file:line and the triggering value.","If the panic is `unknown type in languages config`, a language entry has a non-Params/non-merge-strategy type; normalize it.","Reduce config to a minimal repro and report the issue with the stack trace if it looks like an internal bug.","Update Hugo to the latest patch release in case the panic is a known fixed defect."],"exampleFix":"# before: a language value is a string instead of a table\n[languages]\nfr = \"french\"\n\n# after\n[languages.fr]\nweight = 20","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Wrap LoadConfig in error handling; panics are already converted to errors\n// by Hugo's recover(), so a normal err check suffices.\ncfgs, err := allconfig.LoadConfig(d)\nif err != nil {\n    // err.Error() begins with \"failed to load config: <panic value>\"\n    // and the stack trace has already been printed to stderr.\n    return err\n}","preventionTips":["Treat any panic-derived message as a likely internal bug; capture the stack trace.","Minimize config to a repro before reporting.","Keep Hugo updated; many panics are fixed in patch releases."],"tags":["config","panic","recovery","internal"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}