gohugoio/hugo · critical

nil deps on site

Error message

nil deps on site

What it means

Panic at the start of processFiles when s.Deps is nil. This method processes content files into the page map and needs the dependency container; like error 780 it guards against a half-initialized HugoSites. It is a redundant invariant check on a different code path within the build.

Source

Thrown at hugolib/hugo_sites_build.go:1350

			s := p.Site.(*Site)
			s.handleContentAdapterChanges(bi, buildConfig)
			return nil
		},
	})

	h.pageTrees.treePagesFromTemplateAdapters.WalkPrefixRaw(doctree.LockTypeRead, "", func(key string, p *pagesfromdata.PagesFromTemplate) (bool, error) {
		if p.StaleVersion() > 0 {
			g.Enqueue(p)
		}
		return false, nil
	})

	return g.Wait()
}

func (s *HugoSites) processFiles(ctx context.Context, l logg.LevelLogger, buildConfig *BuildCfg, filenames ...pathChange) error {
	if s.Deps == nil {
		panic("nil deps on site")
	}

	sourceSpec := source.NewSourceSpec(s.PathSpec, buildConfig.ContentInclusionFilter, s.BaseFs.Content.Fs)

	// For inserts, we can pick an arbitrary pageMap.
	pageMap := s.Sites[0].pageMap

	c := newPagesCollector(ctx, s.h, sourceSpec, s.Log, l, pageMap, buildConfig, filenames)

	if err := c.Collect(); err != nil {
		return err
	}

	return nil
}

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Always construct HugoSites via LoadConfig/NewHugoSites so Deps is populated.
  2. Never nil h.Deps; create a fresh HugoSites for a reconfiguration instead.
  3. In tests, use the provided integration-test builders.
  4. Add a precondition assertion in your wrapper before triggering a build.

Example fix

// before
site := &HugoSites{}
site.processFiles(ctx, l, cfg, changes...) // panic: nil deps on site

// after
site, err := hugolib.NewHugoSitesFromConfig(d, cfg)
if err != nil { return err }
site.processFiles(ctx, l, cfg, changes...)
Defensive patterns

Strategy: validation

Validate before calling

// Same as 780: ensure Deps is populated via standard init before any build that reaches processFiles.

Prevention

When it happens

Trigger: processFiles is invoked during build but Deps was cleared or never set on the HugoSites. Constructing HugoSites manually or niling Deps between operations. Reaching processFiles from a non-standard caller.

Common situations: Embedding Hugo and reusing a HugoSites object after manually tearing down its dependencies. Test harnesses that bypass full init. State cleanup logic that over-nils shared containers.

Related errors


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