gohugoio/hugo · critical

Shifter is required

Error message

Shifter is required

What it means

A panic in doctree.New (hugolib/doctree/nodeshifttree.go:88) when Config.Shifter is nil. The NodeShiftTree relies on the Shifter for all dimension operations (Insert/Delete/Shift), so a nil Shifter is rejected at construction time.

Source

Thrown at hugolib/doctree/nodeshifttree.go:88

)

// NodeShiftTree is the root of a tree that can be shaped using the Shape method.
// Note that multiplied shapes of the same tree is meant to be used concurrently,
// so use the applicable locking when needed.
type NodeShiftTree[T any] struct {
	tree *radix.Tree[T]

	// [language, version, role].
	siteVector     sitesmatrix.Vector
	shifter        Shifter[T]
	transformerRaw Transformer[T]

	mu *sync.RWMutex
}

func New[T any](cfg Config[T]) *NodeShiftTree[T] {
	if cfg.Shifter == nil {
		panic("Shifter is required")
	}

	return &NodeShiftTree[T]{
		mu: &sync.RWMutex{},

		shifter:        cfg.Shifter,
		transformerRaw: cfg.TransformerRaw,
		tree:           radix.New[T](),
	}
}

// SiteVector returns the site vector of the current dimension.
func (r *NodeShiftTree[T]) SiteVector() sitesmatrix.Vector {
	return r.siteVector
}

// Delete deletes the node at the given key in the current dimension.
func (r *NodeShiftTree[T]) Delete(key string) (T, bool) {

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Pass a non-nil Shifter in doctree.Config
  2. Reuse Hugo's contentNodeShifter rather than building one from scratch

Example fix

// before
tree := doctree.New[contentNode](doctree.Config[contentNode]{})
// after
tree := doctree.New[contentNode](doctree.Config[contentNode]{
    Shifter: &contentNodeShifter{},
})
Defensive patterns

Strategy: validation

Validate before calling

if cfg.Shifter == nil {
    return nil, errors.New("doctree.Config.Shifter must be non-nil")
}

Prevention

When it happens

Trigger: Calling doctree.New[T](doctree.Config[T]{}) without setting Shifter.

Common situations: Embedded/programmatic use of Hugo's doctree package without supplying a Shifter implementation.

Related errors


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