caddyserver/caddy · error

adapting config using %s: %v

Error message

adapting config using %s: %v

What it means

The selected adapter ran over the config and returned an error — for the caddyfile adapter this is the classic Caddyfile syntax/semantic error surface (unknown directive, bad site address, malformed block). The message includes the adapter name and the adapter's own detailed error with file/line where available.

Source

Thrown at cmd/main.go:216

	} else if err != nil {
		return nil, "", "", err
	}

	// load config adapter
	if adapterName != "" {
		cfgAdapter = caddyconfig.GetAdapter(adapterName)
		if cfgAdapter == nil {
			return nil, "", "", fmt.Errorf("unrecognized config adapter: %s", adapterName)
		}
	}

	// adapt config
	if cfgAdapter != nil {
		adaptedConfig, warnings, err := cfgAdapter.Adapt(config, map[string]any{
			"filename": configFile,
		})
		if err != nil {
			return nil, "", "", fmt.Errorf("adapting config using %s: %v", adapterName, err)
		}
		logger.Info("adapted config to JSON", zap.String("adapter", adapterName))
		for _, warn := range warnings {
			msg := warn.Message
			if warn.Directive != "" {
				msg = fmt.Sprintf("%s: %s", warn.Directive, warn.Message)
			}
			logger.Warn(msg,
				zap.String("adapter", adapterName),
				zap.String("file", warn.File),
				zap.Int("line", warn.Line))
		}
		config = adaptedConfig
	} else if len(config) != 0 {
		// validate that the config is at least valid JSON
		err = json.Unmarshal(config, new(any))
		if err != nil {
			if jsonErr, ok := err.(*json.SyntaxError); ok {

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Read the embedded adapter error — it usually gives the exact line and token
  2. Run 'caddy fmt --overwrite Caddyfile' to normalize braces/indentation and expose structure errors
  3. Compare against the docs for the failing directive; after upgrades check the changelog for renamed directives
  4. Iterate with 'caddy adapt --config Caddyfile --adapter caddyfile' until it adapts cleanly, then run/reload

Example fix

# before
example.com {
    respond "hi"
# missing closing brace

# after
example.com {
    respond "hi"
}
Defensive patterns

Strategy: validation

Validate before calling

# Dry-run the adaptation in CI to catch Caddyfile errors pre-deploy:
caddy adapt --config Caddyfile --adapter caddyfile > /dev/null

Try / catch

if err := adapt(); err != nil { if strings.Contains(err.Error(), "adapting config using") { /* parse file:line from the inner error and point the editor there */ } }

Prevention

When it happens

Trigger: Caddyfile with a typo'd directive, missing brace, duplicate site block, invalid argument count for a directive, or a site address that fails parsing; JSON adapter strictness failures.

Common situations: Editing a Caddyfile and forgetting a closing brace; upgrading Caddy where a directive was renamed/removed; copy-pasting snippet blocks incorrectly.

Related errors


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