Skip to content

Preserve HTTP body read errors in Go middleware - #4

Merged
edrevo merged 1 commit into
round3ai:mainfrom
ItsM0rty:fix/preserve-body-read-errors
Oct 16, 2026
Merged

edrevo merged 1 commit into
round3ai:mainfrom
ItsM0rty:fix/preserve-body-read-errors

Conversation

@ItsM0rty

Copy link
Copy Markdown
Contributor

The Go observability middleware currently discards errors from io.ReadAll when capturing HTTP bodies. If a body returns bytes followed by io.ErrUnexpectedEOF, the replacement reader returns those bytes with a clean EOF. This changes what the next handler or caller sees.

Keep the captured bytes and replay the original read error after them. Successful reads, nil bodies, and http.NoBody keep their existing behavior.

Added tests for empty and partial bodies with read errors, successful replay, and request/response error propagation through the middleware. The error-preservation tests fail on the original code and pass with this change.

Validation from anthropic-sdk/go/middleware-example:

  • go test ./... -count=1 -v
  • go vet ./...
  • gofmt and git diff --check

Tests use a local HTTP server for reporting. No AWS or three.dev credentials or live services are involved.

@edrevo

edrevo commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Thanks @ItsM0rty !

@edrevo
edrevo merged commit 51021e1 into round3ai:main Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants