From 9cce38e2b6b7453bb4faf19f54aa8ca381af0f87 Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Wed, 18 Sep 2024 13:06:06 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Capture=20underlying=20error=20o?= =?UTF-8?q?n=20codes.DataLoss=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We are throwing away the underlying error. Capturing it to better understand why this happens --- server.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 3545c50..fd0573b 100644 --- a/server.go +++ b/server.go @@ -97,7 +97,7 @@ func (s *server) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - rctx, rcancel, body, err := preProcessRequest(ctx, req) + rctx, rcancel, body, err := preProcessRequest(ctx, span, req) if err != nil { HttpError(span, w, req, err) return @@ -118,11 +118,12 @@ func (s *server) ServeHTTP(w http.ResponseWriter, req *http.Request) { // preProcessRequest is used to preprocess the incoming request. // It returns the context, a cancel function and the body of the request. The cancel function can be used to cancel // the context. It also adds the http headers to the context. -func preProcessRequest(ctx context.Context, req *http.Request) (context.Context, context.CancelFunc, []byte, error) { +func preProcessRequest(ctx context.Context, span trace.Span, req *http.Request) (context.Context, context.CancelFunc, []byte, error) { // read body content body, err := io.ReadAll(req.Body) defer req.Body.Close() if err != nil { + span.RecordError(err) return nil, nil, nil, status.Error(codes.DataLoss, "unrecoverable data loss or corruption") }