caddyserver/caddy · error

adapting config using %s adapter: %v

Error message

adapting config using %s adapter: %v

What it means

Returned with HTTP 400 when the resolved config adapter's Adapt() call fails on the request body. For the caddyfile adapter this covers Caddyfile syntax errors, unknown directives/site addresses, and invalid blocks. The error message names the adapter and chains the adapter's own diagnostic, which usually includes the file line number.

Source

Thrown at caddyconfig/load.go:211

	// if already JSON, no need to adapt
	if strings.HasSuffix(ct, "/json") {
		return body, nil, nil
	}

	// adapter name should be suffix of MIME type
	_, adapterName, slashFound := strings.Cut(ct, "/")
	if !slashFound {
		return nil, nil, fmt.Errorf("malformed Content-Type")
	}

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

	result, warnings, err := cfgAdapter.Adapt(body, nil)
	if err != nil {
		return nil, nil, fmt.Errorf("adapting config using %s adapter: %v", adapterName, err)
	}

	return result, warnings, nil
}

var bufPool = sync.Pool{
	New: func() any {
		return new(bytes.Buffer)
	},
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Test locally first: caddy validate --config Caddyfile --adapter caddyfile shows the exact line and cause
  2. Use POST /adapt (not /load) to dry-run adaptation without applying the config
  3. Read the chained error — the caddyfile adapter reports line numbers of the offending token

Example fix

# before
curl -X POST http://localhost:2019/load -H 'Content-Type: text/caddyfile' -d @Caddyfile  # fails
# after
caddy validate --config Caddyfile --adapter caddyfile && curl -X POST http://localhost:2019/load -H 'Content-Type: text/caddyfile' -d @Caddyfile
Defensive patterns

Strategy: validation

Validate before calling

// dry-run adaptation via POST /adapt; only /load on success
req, _ := http.NewRequestWithContext(ctx, "POST", admin+"/adapt", bytes.NewReader(src))
req.Header.Set("Content-Type", "text/caddyfile")
resp, err := client.Do(req)
if err != nil { return err }
if resp.StatusCode != http.StatusOK {
    b, _ := io.ReadAll(resp.Body)
    return fmt.Errorf("adaptation failed (fix source before loading): %s", b)
}

Try / catch

if resp.StatusCode == http.StatusBadRequest && strings.Contains(bodyText, "adapting config using") {
    // chained error contains Caddyfile line info; surface it, do not retry
    return fmt.Errorf("caddyfile error: %s", bodyText)
}

Prevention

When it happens

Trigger: POSTing a Caddyfile with syntax errors (unclosed braces, wrong directive order) to /load or /adapt with Content-Type: text/caddyfile; using a directive from a plugin not compiled in; global options block mistakes; environment variable placeholders that fail to expand.

Common situations: Editing a Caddyfile by hand and pushing via the admin API without testing; CI pushing a template-rendered Caddyfile where a variable rendered empty; upgrading Caddy where a directive was renamed or removed.

Related errors


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