gohugoio/hugo · error

config not set

Error message

config not set

What it means

hugoBuilder.withConfE guards every access to the shared commonConfig; if c.conf is nil when a command tries to use it, the guard returns errConfigNotSet. This protects against commands running before configuration has been loaded.

Solutions

  1. Ensure config loads successfully before invoking builder operations (fix the underlying config load error)
  2. Confirm a valid Hugo project / config file exists in the working directory
  3. Restart the server after fixing config so c.conf is repopulated
Defensive patterns

Strategy: validation

Try / catch

if err := builder.withConfE(func(conf *commonConfig) error { ... }); err != nil {
    if errors.Is(err, errConfigNotSet) { /* load config first, then retry */ }
}

Prevention

When it happens

Trigger: Calling a hugoBuilder method that routes through withConfE before c.conf has been populated by doConfigReload/ConfigFromProvider.

Common situations: A command path that skips config loading; a reload failure left c.conf nil; invoking builder helpers during early init.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/6bbc68262d501eb3. Report an issue: GitHub.

Appendix: 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 52c9bd7908)