{"record":{"id":"3e63279c1fd34829","repo":"caddyserver/caddy","slug":"encoding-config-v","errorCode":null,"errorMessage":"encoding config: %v","messagePattern":"encoding config: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"admin.go","lineNumber":1229,"sourceCode":"\t\t\t\tvar idx int\n\t\t\t\tif method != http.MethodPost {\n\t\t\t\t\tidxStr := parts[len(parts)-1]\n\t\t\t\t\tidx, err = parseCanonicalArrayIndex(idxStr)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"[%s] invalid array index '%s': %v\",\n\t\t\t\t\t\t\tpath, idxStr, err)\n\t\t\t\t\t}\n\n\t\t\t\t\tif idx < 0 || (method != http.MethodPut && idx >= len(arr)) || idx > len(arr) {\n\t\t\t\t\t\treturn fmt.Errorf(\"[%s] array index out of bounds: %s\", path, idxStr)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tswitch method {\n\t\t\t\tcase http.MethodGet:\n\t\t\t\t\terr = enc.Encode(arr[idx])\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"encoding config: %v\", err)\n\t\t\t\t\t}\n\t\t\t\tcase http.MethodPost:\n\t\t\t\t\tif ellipses {\n\t\t\t\t\t\tvalArray, ok := val.([]any)\n\t\t\t\t\t\tif !ok {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"final element is not an array\")\n\t\t\t\t\t\t}\n\t\t\t\t\t\tv[part] = append(arr, valArray...)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tv[part] = append(arr, val)\n\t\t\t\t\t}\n\t\t\t\tcase http.MethodPut:\n\t\t\t\t\t// avoid creation of new slice and a second copy (see\n\t\t\t\t\t// https://github.com/golang/go/wiki/SliceTricks#insert)\n\t\t\t\t\tarr = append(arr, nil)\n\t\t\t\t\tcopy(arr[idx+1:], arr[idx:])\n\t\t\t\t\tarr[idx] = val\n\t\t\t\t\tv[part] = arr","sourceCodeStart":1211,"sourceCodeEnd":1247,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/admin.go#L1211-L1247","documentation":"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.","triggerScenarios":"GET /config/.../somearray/N where the response writer fails: client cancels the request, connection reset, or response stream closed before encoding completes.","commonSituations":"Client timeouts on very large config payloads; proxies closing slow responses. Almost never a config-content problem.","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"],"exampleFix":"# before\ncurl -m 1 http://localhost:2019/config/apps/http/servers/myserver/routes/0  # 1s timeout\n# after\ncurl -m 30 http://localhost:2019/config/apps/http/servers/myserver/routes/0","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Retry the GET once with a longer timeout; encode failures on plain JSON data are almost always transport (client disconnect) failures, not data problems.","preventionTips":["Set generous timeouts for large config reads","Fetch narrow subtrees rather than whole apps"],"tags":["caddy","admin-api","json","encoding","io"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}