caddyserver/caddy · error

re-encoding module configuration: %v

Error message

re-encoding module configuration: %v

What it means

After extracting the module-name key, getModuleNameInline re-marshals the remaining map back to JSON. json.Marshal of a map[string]any derived from valid JSON essentially cannot fail (the only theoretical failures involve unsupported values like NaN or cyclic structures, which JSON decoding cannot produce), so this error is near-unreachable in practice.

Source

Thrown at modules.go:282

	var tmp map[string]any
	err := json.Unmarshal(raw, &tmp)
	if err != nil {
		return "", nil, err
	}

	moduleName, ok := tmp[moduleNameKey].(string)
	if !ok || moduleName == "" {
		return "", nil, fmt.Errorf("module name not specified with key '%s' in %+v", moduleNameKey, tmp)
	}

	// remove key from the object, otherwise decoding it later
	// will yield an error because the struct won't recognize it
	// (this is only needed because we strictly enforce that
	// all keys are recognized when loading modules)
	delete(tmp, moduleNameKey)
	result, err := json.Marshal(tmp)
	if err != nil {
		return "", nil, fmt.Errorf("re-encoding module configuration: %v", err)
	}

	return moduleName, result, nil
}

// Provisioner is implemented by modules which may need to perform
// some additional "setup" steps immediately after being loaded.
// Provisioning should be fast (imperceptible running time). If
// any side-effects result in the execution of this function (e.g.
// creating global state, any other allocations which require
// garbage collection, opening files, starting goroutines etc.),
// be sure to clean up properly by implementing the CleanerUpper
// interface to avoid leaking resources.
type Provisioner interface {
	Provision(Context) error
}

// Validator is implemented by modules which can verify that their

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Treat it as a bug: report the config and stack trace to the project.
  2. Re-check that the config file is valid JSON from scratch (re-save with UTF-8, no BOM, no control characters).
  3. Retry with a freshly adapted config from 'caddy adapt'.
Defensive patterns

Strategy: try-catch

Try / catch

if err := caddy.Validate(cfg); err != nil {
    if strings.Contains(err.Error(), "re-encoding module configuration") {
        // effectively unreachable — file a bug with the config and stack trace
    }
    return err
}

Prevention

When it happens

Trigger: Effectively unreachable through config loading; conceivably triggered by a Go map with non-marshalable values if internal callers ever pass hand-constructed maps rather than decoded JSON.

Common situations: If it ever appears, suspect memory corruption or a bug in a custom integration that calls internal JSON loading paths with non-JSON-derived data.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/7b7d165b8d8ab95f. Report an issue: GitHub.