{"id":"88d4e453dc091c34","repo":"gohugoio/hugo","slug":"errconfignotset","errorCode":"errConfigNotSet","errorMessage":"config not set","messagePattern":"config not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/hugobuilder.go","lineNumber":81,"sourceCode":"\t// May be nil.\n\ts *serverCommand\n\n\t// Currently only set when in \"fast render mode\".\n\tchangeDetector *fileChangeDetector\n\tvisitedURLs    *types.EvictingQueue[string]\n\n\tfullRebuildSem *semaphore.Weighted\n\tdebounce       func(f func())\n\n\tonConfigLoaded func(reloaded bool) error\n\n\tfastRenderMode     bool\n\tshowErrorInBrowser bool\n\n\terrState hugoBuilderErrState\n}\n\nvar errConfigNotSet = errors.New(\"config not set\")\n\nfunc (c *hugoBuilder) withConfE(fn func(conf *commonConfig) error) error {\n\tc.confmu.Lock()\n\tdefer c.confmu.Unlock()\n\tif c.conf == nil {\n\t\treturn errConfigNotSet\n\t}\n\treturn fn(c.conf)\n}\n\nfunc (c *hugoBuilder) withConf(fn func(conf *commonConfig)) {\n\tc.confmu.Lock()\n\tdefer c.confmu.Unlock()\n\tfn(c.conf)\n}\n\nfunc (c *hugoBuilder) withConfOrOldConf(fn func(conf *commonConfig)) {\n\tc.confmu.Lock()","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/hugobuilder.go#L63-L99","documentation":"A sentinel error (errConfigNotSet) returned by hugoBuilder.withConfE and withConfOrOldConfE when the builder's commonConfig has not been loaded yet (c.conf is nil, and for the OrOld variant c.confOld is also nil). It guards against operating on a builder before loadConfig has succeeded, or during a config reload window when c.conf is temporarily set to nil.","triggerScenarios":"Any code path calling withConfE/withConfOrOldConfE before hugoBuilder.loadConfig completes, or during reloadConfig where c.conf is nil-ed while ConfigFromConfig runs and both conf and confOld are unavailable; also if the initial config load failed and a later build/watch callback still fires.","commonSituations":"Hitting a file-watch rebuild while the initial config load failed (e.g. broken hugo.toml during `hugo server`), or race-adjacent scenarios where a server callback runs before the first successful config load.","solutions":["Fix whatever made the initial config load fail (check earlier error output for the real config error) and rerun the command.","If running `hugo server`, restart the server so a clean config load happens before builds.","If developing against this code, ensure loadConfig is called and returns nil before invoking build/watch methods on hugoBuilder."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure config is loaded before building\nif cfg == nil {\n    log.Fatal(\"load config before invoking build\")\n}\nb := newHugoBuilder(r, cfg)","typeGuard":null,"tryCatchPattern":"if err := b.build(); err != nil {\n    if err.Error() == \"config not set\" {\n        // programming error: builder used before initialization\n        panic(err)\n    }\n    return err\n}","preventionTips":["Always call the config-loading step (e.g. loadConfig) before constructing/using the builder","Treat this as an invariant violation, not a runtime condition — fix call order rather than handling it","Use a constructor that requires config as a parameter so an unset config can't compile"],"tags":["hugo","config","lifecycle","go"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}