JuliusBrussee/caveman · error
rewriter: encode request: %w
Error message
rewriter: encode request: %w
What it means
Client.do failed to JSON-marshal the request body map before sending it to the rewriter provider. This indicates a non-serializable value (NaN/Inf float, channel, func) was placed into the body — a programming bug in the caller building the request, not a provider-side fault.
Source
Thrown at rewriter/provider.go:175
}, nil
}
// openAIAcceptsTemperature reports whether a chat-completions model still takes
// a caller-set temperature. The reasoning families (gpt-5*, o1/o3/o4*) do not.
func openAIAcceptsTemperature(model string) bool {
name := strings.ToLower(strings.TrimSpace(model))
for _, prefix := range []string{"gpt-5", "o1", "o3", "o4"} {
if name == prefix || strings.HasPrefix(name, prefix+"-") || strings.HasPrefix(name, prefix+".") {
return false
}
}
return true
}
func (c *Client) do(ctx context.Context, endpoint string, body map[string]any, headers map[string]string) ([]byte, error) {
encoded, err := json.Marshal(body)
if err != nil {
return nil, fmt.Errorf("rewriter: encode request: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(encoded))
if err != nil {
return nil, fmt.Errorf("rewriter: build request: %w", err)
}
req.Header.Set("content-type", "application/json")
for key, value := range headers {
req.Header.Set(key, value)
}
resp, err := c.doer(req)
if err != nil {
return nil, fmt.Errorf("rewriter: %s: %w", endpoint, err)
}
// An injected doer is caller code; a nil response or body must surface as an
// error rather than a panic inside the proxy hot path.
if resp == nil {
return nil, fmt.Errorf("rewriter: %s: nil response", endpoint)View on GitHub (pinned to 766dce6b13)
Solutions
- Ensure the request body map contains only JSON-serializable values
- Sanitize or omit NaN/Inf floats before building the rewriter request
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at rewriter/provider.go:175 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/151bfb0ddbcc869a.
Report an issue: GitHub.