Loading
feat(v2/httpserver): add PanicRecoveryMiddleware
Summary
- Adds
PanicRecoveryMiddlewaretov2/httpserverthat recovers from application handler panics, logs a structuredERRORentry with the panic value, stack trace, HTTP method, and URI, records the error on the active OTel span, and returns500 Internal Server Errorto the client - Includes a
panicResponseWritersentinel that prevents a duplicateWriteHeader(500)when the handler began writing before panicking - Wires
PanicRecoveryMiddlewareunconditionally as the innermost middleware inNewWithConfig, so all LabKit HTTP servers get automatic panic recovery without any consumer-side changes
Test plan
-
TestPanicRecoveryMiddleware— 5 table-driven unit tests covering: no panic passthrough, string panic, error panic, nil panic, headers-already-written guard -
TestNewWithConfig_PanicRecoveryMiddleware— integration test vias.ServeHTTPassertingNotPanicsand500status - Run
go test ./httpserver/... -vinv2/— all tests pass - Run golangci-lint — clean