caddyserver/caddy · warning
encoding config: %v
Error message
encoding config: %v
What it means
Returned when json.Encoder fails while serializing an array element selected by GET on an array destination in the config. Since the config tree holds plain values decoded from JSON, encoding virtually never fails; the realistic failure is the underlying io.Writer (the HTTP response) erroring, e.g. client disconnected mid-encode.
Source
Thrown at admin.go:1229
var idx int
if method != http.MethodPost {
idxStr := parts[len(parts)-1]
idx, err = parseCanonicalArrayIndex(idxStr)
if err != nil {
return fmt.Errorf("[%s] invalid array index '%s': %v",
path, idxStr, err)
}
if idx < 0 || (method != http.MethodPut && idx >= len(arr)) || idx > len(arr) {
return fmt.Errorf("[%s] array index out of bounds: %s", path, idxStr)
}
}
switch method {
case http.MethodGet:
err = enc.Encode(arr[idx])
if err != nil {
return fmt.Errorf("encoding config: %v", err)
}
case http.MethodPost:
if ellipses {
valArray, ok := val.([]any)
if !ok {
return fmt.Errorf("final element is not an array")
}
v[part] = append(arr, valArray...)
} else {
v[part] = append(arr, val)
}
case http.MethodPut:
// avoid creation of new slice and a second copy (see
// https://github.com/golang/go/wiki/SliceTricks#insert)
arr = append(arr, nil)
copy(arr[idx+1:], arr[idx:])
arr[idx] = val
v[part] = arrView on GitHub (pinned to 50e54ee279)
Solutions
- Increase client timeout and retry the GET for large configs
- If it recurs, check for a proxy between you and the admin endpoint dropping the connection
Example fix
# before curl -m 1 http://localhost:2019/config/apps/http/servers/myserver/routes/0 # 1s timeout # after curl -m 30 http://localhost:2019/config/apps/http/servers/myserver/routes/0
Defensive patterns
Strategy: retry
Try / catch
Retry the GET once with a longer timeout; encode failures on plain JSON data are almost always transport (client disconnect) failures, not data problems.
Prevention
- Set generous timeouts for large config reads
- Fetch narrow subtrees rather than whole apps
When it happens
Trigger: GET /config/.../somearray/N where the response writer fails: client cancels the request, connection reset, or response stream closed before encoding completes.
Common situations: Client timeouts on very large config payloads; proxies closing slow responses. Almost never a config-content problem.
Related errors
- decoding request body: %w, at offset %d
- decoding request body: %w
- final element is not an array
- encoding new config: %v
- missing 'req' argument
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/3e63279c1fd34829.
Report an issue: GitHub.