-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Feat: Error Cause Extractor #1198
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, I like it! I'm already thinking about all the ways to make use of this, haha.
Instead of returning a list, we just return the cause, making it easier to apply the recursion, as we don't have to deal with lists of lists or injecting extractors in other extractors. It also makes the interface simpler to understand.
My thinking was, that there's maybe something similar to C#'s AggregateException
, which could be supported, too. I've never seen something like that in Dart, though.
Apart from whether that should be supported or not, you could easily support that by changing current
to a stack and letting the CauseExtractor return a list.
@denrase sounds like a good option, nice. |
Yea I like this as well :) |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## v7.0.0 #1198 +/- ##
=========================================
Coverage ? 88.94%
=========================================
Files ? 125
Lines ? 3827
Branches ? 0
=========================================
Hits ? 3404
Misses ? 423
Partials ? 0 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@marandaneto @ueman I have added a check for circularity and also more unit tests. Think we could do a first review of this approach and afterwards document the new classes/method if it's the way we want to go. |
To get the original throwable we could run the extractor again on the initial throwable. That way we have them in hand. The list of these and the list of sentry exceptions in the event "should" have the same order, so we could match them with the index. What I'm not sure about is how to "migrate" the dio event processor though, as it does something different. If we provide an extractor for the |
Can't we just add the throwable to the |
yeah, I was thinking about this as well, the |
That would make things easier, whats your take on this @marandaneto ? |
Get your point, but the processor does something that the new approach would do, which is converting the inner exception to a sentry exception, also its stack trace, this at least should be possible. |
@ueman @marandaneto I tried to apply the new approach in the dio event processor in combination with an dio error extractor. WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it
dio/lib/src/dio_event_processor.dart
Outdated
final exceptions = _removeDioErrorStackTraceFromValue( | ||
List<SentryException>.from(event.exceptions ?? <SentryException>[]), | ||
dioError, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it wouldn't look as nice without this code, I think it would greatly simplify the code if we just remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion here, opted to keep the previous functionality intact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it for now. Lets see if @marandaneto also has an opinion here.
@@ -0,0 +1,6 @@ | |||
class ExceptionCause { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add docs for public classes and properties, that apply to some other files as well.
final extractor = | ||
_options.exceptionCauseExtractor(extractionSourceSource.runtimeType); | ||
|
||
currentExceptionCause = extractor?.cause(extractionSourceSource); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to wrap that with a try-catch, otherwise, we will silently swallow the exception in case the extract has a bug.
Logging the error too.
// Add to get inner exception & stacktrace | ||
options.addExceptionCauseExtractor(DioErrorExtractor()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to do something similar to the lines below here, L27-28, only adding the dio extractor if already not there, just for defense programming, otherwise calling this extension multiple times would add multiple extractors, maybe causing side effects.
📜 Description
Relates to #1045
Introduce a way for errors to provide a
cause
to the SDK, so we can extract it.💡 Motivation and Context
This builds on the discussions in #1045. Instead of returning a list, we just return the cause, making it easier to apply the recursion, as we don't have to deal with lists of lists or injecting extractors in other extractors. It also makes the interface simpler to understand.
So the goal is for users to register the cause extractors for their own application errors, or for any other 3rd party object where they want to extract an error cause. The SDK would then try to flatten errors & then transform with error/stacktrace factories. Event processors can check the throwable list in the event and use the data as needed.
💚 How did you test it?
📝 Checklist
🔮 Next steps
This is pretty much a small POC. Would be great if you (@marandaneto & @ueman) could give me some feedback on this approach, before I'll continue with the "real" implementation.