gohugoio/hugo · error

failed to create config from result: %w

Error message

failed to create config from result: %w

What it means

Returned when fromLoadConfigResult fails on the first pass — i.e. the raw merged config parsed fine, but constructing the typed per-language Config objects from it failed. This is where the alldecoders.go decoder table runs, so it wraps section-level decode/validation errors (languages, markup, outputs, security, related, ...) into one 'failed to create config from result' error.

Source

Thrown at config/allconfig/load.go:73

	}

	if d.Logger == nil {
		d.Logger = loggers.NewDefault()
	}

	l := &configLoader{ConfigSourceDescriptor: d, cfg: config.New()}
	// Make sure we always do this, even in error situations,
	// as we have commands (e.g. "hugo mod init") that will
	// use a partial configuration to do its job.
	defer l.deleteMergeStrategies()
	res, _, err := l.loadConfigMain(d)
	if err != nil {
		return nil, fmt.Errorf("failed to load config: %w", err)
	}

	configs, err = fromLoadConfigResult(d.Fs, d.Logger, res)
	if err != nil {
		return nil, fmt.Errorf("failed to create config from result: %w", err)
	}

	moduleConfig, modulesClient, err := l.loadModules(configs, d.IgnoreModuleDoesNotExist)
	if err != nil {
		return nil, fmt.Errorf("failed to load modules: %w", err)
	}

	if len(l.ModulesConfigFiles) > 0 {
		// Config merged in from modules.
		// Re-read the config.
		configs, err = fromLoadConfigResult(d.Fs, d.Logger, res)
		if err != nil {
			return nil, fmt.Errorf("failed to create config from modules config: %w", err)
		}
		if err := configs.transientErr(); err != nil {
			return nil, fmt.Errorf("failed to create config from modules config: %w", err)
		}
		configs.LoadingInfo.ConfigFiles = append(configs.LoadingInfo.ConfigFiles, l.ModulesConfigFiles...)

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Look at the wrapped error after the prefix — it names the failing section (e.g. 'failed to decode languages config') and the actual problem.
  2. Fix the identified section against the current Hugo docs for your version.
  3. If the error appeared after a Hugo upgrade, check the release notes for renamed/removed config keys in that section.
  4. Bisect by temporarily removing the implicated section to confirm, then reintroduce it corrected.
Defensive patterns

Strategy: try-catch

Validate before calling

// Most 'create config from result' failures are type mismatches; keep values typed correctly
// e.g. booleans as true/false not "true", ints unquoted, durations/strings where documented

Try / catch

conf, err := allconfig.LoadConfig(opts)
if err != nil {
    // decode-stage failure: the raw files parsed but a key had the wrong type/shape
    // the wrapped mapstructure error names the offending key — surface it verbatim
    return err
}

Prevention

When it happens

Trigger: Any decoder in allDecoderSetups returning an error while transforming the merged config map into the typed Config: an invalid security whitelist regexp, bad [languages] or [related] blocks, invalid output formats or media types, unknown markup settings — anything that parses as TOML/YAML but is semantically invalid.

Common situations: Config that is syntactically valid but semantically wrong: values of the wrong type in a known section, options from a newer Hugo used on an older binary, theme-recommended config pasted without adaptation, per-language overrides that conflict with root settings.

Related errors


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