HTTPErrorHandler stacktrace #2278
-
Hello ! I am currently trying to report our API errors to the GCP error reporting service through echo's HTTPErrorHandler. Here is the code I'm using to test this: e := echo.New()
e.HTTPErrorHandler = func(err error, c echo.Context) {
errorClient.Report(errorreporting.Entry{
Error: err,
Req: c.Request(),
})
e.DefaultHTTPErrorHandler(err, c)
} The reporting in itself works perfectly, the issue is I am losing all the stacktrace information with this method, which is quiet essential to debug errors. Here is an example stacktrace I receive on GCP (I filtered some information for privacy purposes) through the HTTPErrorHandler:
So, I'm now wondering if there is still a way to use the HTTPErrorHandler and keeping the original stacktrace ? I'd rather not have to call I've also seen this issue but the only solution offered is to wrap errors to pack the stacktrace in it 😕 I'm asking again because the issue is from 5 years ago. Thanks for any feedback ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The way handler/middleware chain works makes it not possible to have stacktrace as error value is returned - and calling methods/functions do not have in Go any mechanism of knowing what the method call stack was when that particular (error) object was created. unless the place that created what error encapsulates stacktrace there. Basically you have to adopt Go way and let go of Java etc exceptions and their stacktraces or start initiating error objects with by embedding stack information at the time when that error object is created. I think there is somewhere blogpost or something from Go authors that if you want something tracelike - start wrapping errors places where you handle them. |
Beta Was this translation helpful? Give feedback.
The way handler/middleware chain works makes it not possible to have stacktrace as error value is returned - and calling methods/functions do not have in Go any mechanism of knowing what the method call stack was when that particular (error) object was created. unless the place that created what error encapsulates stacktrace there.
Basically you have to adopt Go way and let go of Java etc exceptions and their stacktraces or start initiating error objects with by embedding stack information at the time when that error object is created.
I think there is somewhere blogpost or something from Go authors that if you want something tracelike - start wrapping errors places where you handle them.