Repository navigation
🐛 Fix rethrown exceptions not properly preserving stacktrace - #412
Merged
Merged
Conversation
Dart has "rethrow" within catch blocks to preserve stack traces, and Futures will preserve stack traces if you "throw" the same exception so long as it is not inside an `async` block. The `close` method had its `onError` marked as async by accident, so it was not preserving the stack trace properly. Fixes RUMM-3264
xgouchet
approved these changes
May 3, 2023
0xnm
reviewed
May 3, 2023
| _handleError(e, st, methodName, logger, attributes)); | ||
| result.catchError((dynamic e, StackTrace st) { | ||
| if (!_handleError(e, st, methodName, logger, attributes)) { | ||
| throw e; |
Member
There was a problem hiding this comment.
should it be still throw e here and not rethrow? All the cases below with _handleError calls are using rethrow.
Member
Author
There was a problem hiding this comment.
🤔 I was going to say yes because unfortunately you can't rethrow outside a catch block, but looking more into catchError I need to change how this works a bit.
Member
Author
There was a problem hiding this comment.
Okay updated. I thought catchError worked like then, which will preserve the stacktrace if you throw synchronously. It turns out, no, you should supply a test function to catchError that returns true if you will handle the exception, and passes it on to the Future otherwise.
Thanks for pointing this out!
0xnm
approved these changes
May 3, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why?
Dart has "rethrow" within catch blocks to preserve stack traces, and Futures will preserve stack traces if you "throw" the same exception so long as it is not inside an
asyncblock. Theclosemethod had itsonErrormarked as async by accident, so it was not preserving the stack trace properly.Fixes RUMM-3264
Review checklist
CI Configuration (optional)