gohugoio/hugo · error

no related config provided

Error message

no related config provided

What it means

`related.DecodeConfig` (related/inverted_index.go:559) refuses a nil params map. It distinguishes "no config passed at all" (nil) from "empty config" — a nil map means the caller invoked config decoding without any `related` section value, which is a programming/config-plumbing error rather than a user choosing empty settings.

Source

Thrown at related/inverted_index.go:561

			}
		}
	}

	return result, nil
}

// normalizes num to a number between 0 and 100.
func norm(num, min, max int) int {
	if min > max {
		panic("min > max")
	}
	return int(math.Floor((float64(num-min) / float64(max-min) * 100) + 0.5))
}

// DecodeConfig decodes a slice of map into Config.
func DecodeConfig(m hmaps.Params) (Config, error) {
	if m == nil {
		return Config{}, errors.New("no related config provided")
	}

	if len(m) == 0 {
		return Config{}, errors.New("empty related config provided")
	}

	var c Config

	if err := mapstructure.WeakDecode(m, &c); err != nil {
		return c, err
	}

	if c.Threshold < 0 || c.Threshold > 100 {
		return Config{}, errors.New("related threshold must be between 0 and 100")
	}

	if c.ToLower {
		for i := range c.Indices {

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Remove the bare `related:` key from the site config, or give it actual content (indices, threshold).
  2. In code, only call DecodeConfig when a non-nil related config map exists; otherwise use related.DefaultConfig.

Example fix

# before (hugo.yaml)
related:
# after
related:
  threshold: 80
  indices:
    - name: keywords
      weight: 100
Defensive patterns

Strategy: validation

Validate before calling

cfg := related.DecodeConfig(p) // or use related.DefaultConfig
if cfg == nil {
    cfg = &related.DefaultConfig
}

Type guard

func hasRelatedConfig(cfg *related.Config) bool { return cfg != nil }

Try / catch

idx, err := related.NewInvertedIndex(cfg)
if err != nil {
    return fmt.Errorf("related config missing — set [related] in site config or use defaults: %w", err)
}

Prevention

When it happens

Trigger: Calling related.DecodeConfig(nil) — in Hugo this happens if the config loader passes a nil Params for the `related` key instead of omitting the decode entirely.

Common situations: Custom Hugo forks/tools invoking DecodeConfig directly with nil; a `related:` key present in config but with a null value (e.g. `related:` alone on a line in YAML yields nil).

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/53687f450e69b5ee.json. Report an issue: GitHub ↗.