-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Go 1.20 Unwrap() with a slice of errors #693
Comments
Thanks, makes sense, added to the backlog. |
What should we do ? Get the first error in the slice ? Or explore the error's tree recursively (but the exceptions are a simple slice) |
The Python API seems to already have a handler for a similar mechanism called Perhaps the same flatting algorithm could be used? |
I'm not very familiar with Python, sorry 😅 |
Neither do I really, heh. My point was more that there are similar idioms in other languages, and when the Sentry team starts working on the issue, they should probably follow the same principles as the APIs in those languages do. And yes, it seems to add them one after the other, at least based on what I can read. |
This ? // SetException appends the unwrapped errors to the event's exception list.
//
// maxErrorDepth is the maximum depth of the error chain we will look
// into while unwrapping the errors.
func (e *Event) SetException(exception error, maxErrorDepth int) {
err := exception
if err == nil {
return
}
e.setException(err, maxErrorDepth)
// Add a trace of the current stack to the most recent error in a chain if
// it doesn't have a stack trace yet.
// We only add to the most recent error to avoid duplication and because the
// current stack is most likely unrelated to errors deeper in the chain.
if e.Exception[0].Stacktrace == nil {
e.Exception[0].Stacktrace = NewStacktrace()
}
// event.Exception should be sorted such that the most recent error is last.
reverse(e.Exception)
}
func (e *Event) setException(err error, maxErrorDepth int) {
for i := 0; i < maxErrorDepth && err != nil; i++ {
e.Exception = append(e.Exception, Exception{
Value: err.Error(),
Type: reflect.TypeOf(err).String(),
Stacktrace: ExtractStacktrace(err),
})
switch previous := err.(type) {
case interface{ Unwrap() error }:
err = previous.Unwrap()
case interface{ Unwrap() []error }:
errs := previous.Unwrap()
for _, errw := range errs {
e.setException(errw, maxErrorDepth-i-1)
}
err = nil
case interface{ Cause() error }:
err = previous.Cause()
default:
err = nil
}
}
} |
Seems like supporting these kind of error groups is a newish feature, see: getsentry/sentry#37716 |
Here's the sentry-javascript implementation, so this change will be a bit more involved. |
hello! any progress? Also joinError does not get proper stack trace too. |
No progress, still in our backlog. |
Summary
Go 1.20 added another way to unwrap errors,
interface { Unwrap() []error }
. As far as I can see, as of nowEvent.SetException
doesn't support it.sentry-go/interfaces.go
Lines 356 to 363 in cda691d
Motivation
Developers are updating to Go 1.20, as Go 1.19 is EOL now, and they will expect sentry-go to support the new interface and include all errors into the event data.
Additional Context
The text was updated successfully, but these errors were encountered: