gohugoio/hugo · error
errConfigNotSet
errConfigNotSet
Error message
config not set
What it means
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.
Source
Thrown at commands/hugobuilder.go:81
// May be nil.
s *serverCommand
// Currently only set when in "fast render mode".
changeDetector *fileChangeDetector
visitedURLs *types.EvictingQueue[string]
fullRebuildSem *semaphore.Weighted
debounce func(f func())
onConfigLoaded func(reloaded bool) error
fastRenderMode bool
showErrorInBrowser bool
errState hugoBuilderErrState
}
var errConfigNotSet = errors.New("config not set")
func (c *hugoBuilder) withConfE(fn func(conf *commonConfig) error) error {
c.confmu.Lock()
defer c.confmu.Unlock()
if c.conf == nil {
return errConfigNotSet
}
return fn(c.conf)
}
func (c *hugoBuilder) withConf(fn func(conf *commonConfig)) {
c.confmu.Lock()
defer c.confmu.Unlock()
fn(c.conf)
}
func (c *hugoBuilder) withConfOrOldConf(fn func(conf *commonConfig)) {
c.confmu.Lock()View on GitHub ↗ (pinned to 8a468df065)
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.
Defensive patterns
Strategy: validation
Validate before calling
// ensure config is loaded before building
if cfg == nil {
log.Fatal("load config before invoking build")
}
b := newHugoBuilder(r, cfg) Try / catch
if err := b.build(); err != nil {
if err.Error() == "config not set" {
// programming error: builder used before initialization
panic(err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to compile whitelist pattern %q: %w
- failed to load config: %v
- failed to init config: %w
- no filesystem provided
- failed to parse timeout: %s
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/88d4e453dc091c34.json.
Report an issue: GitHub ↗.