Skip to content

🐛 Fix rethrown exceptions not properly preserving stacktrace - #412

Merged
fuzzybinary merged 2 commits into
developfrom
RUMM-3264-rethrow
May 3, 2023
Merged

fuzzybinary merged 2 commits into
developfrom
RUMM-3264-rethrow

Conversation

@fuzzybinary

Copy link
Copy Markdown
Member

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 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

Review checklist

  • This pull request has appropriate unit and / or integration tests
  • This pull request references a Github or JIRA issue

CI Configuration (optional)

  • Run unit tests
  • Run integration tests

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
@fuzzybinary
fuzzybinary requested a review from a team as a code owner May 2, 2023 19:41
_handleError(e, st, methodName, logger, attributes));
result.catchError((dynamic e, StackTrace st) {
if (!_handleError(e, st, methodName, logger, attributes)) {
throw e;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be still throw e here and not rethrow? All the cases below with _handleError calls are using rethrow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@fuzzybinary
fuzzybinary requested a review from 0xnm May 3, 2023 13:47
@fuzzybinary
fuzzybinary merged commit 494f5e7 into develop May 3, 2023
@fuzzybinary
fuzzybinary deleted the RUMM-3264-rethrow branch May 3, 2023 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants