{"record":{"id":"6cd67792a8543237","repo":"JuliusBrussee/caveman","slug":"rewriter-response-exceeds-d-bytes","errorCode":null,"errorMessage":"rewriter: response exceeds %d bytes","messagePattern":"rewriter: response exceeds (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rewriter/provider.go","lineNumber":209,"sourceCode":"\t// error rather than a panic inside the proxy hot path.\n\tif resp == nil {\n\t\treturn nil, fmt.Errorf(\"rewriter: %s: nil response\", endpoint)\n\t}\n\tif resp.Body == nil {\n\t\tresp.Body = http.NoBody\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode < 200 || resp.StatusCode > 299 {\n\t\tdetail, _ := io.ReadAll(io.LimitReader(resp.Body, maxErrorBody))\n\t\treturn nil, fmt.Errorf(\"rewriter: %s: status %d: %s\", endpoint, resp.StatusCode, strings.TrimSpace(string(detail)))\n\t}\n\traw, err := io.ReadAll(io.LimitReader(resp.Body, maxProviderResponseBody+1))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"rewriter: read response: %w\", err)\n\t}\n\tif len(raw) > maxProviderResponseBody {\n\t\treturn nil, fmt.Errorf(\"rewriter: response exceeds %d bytes\", maxProviderResponseBody)\n\t}\n\treturn raw, nil\n}\n","sourceCodeStart":191,"sourceCodeEnd":213,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/rewriter/provider.go#L191-L213","documentation":"The rewriter provider's response body exceeded maxProviderResponseBody bytes; the code deliberately reads one byte past the limit to distinguish over-limit from exact-limit and fails closed. This bounds memory use against misbehaving or malicious endpoints and prevents parsing unbounded provider output.","triggerScenarios":"Thrown at rewriter/provider.go:209 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Treat the provider as misconfigured or hostile and refuse its output","Raise the configured response ceiling only if the provider legitimately returns larger completions","Skip the rewrite; the gate records the rejection without forwarding the bytes"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}