Skip to content
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

fix: fix the scope of recover() #1672

Merged
merged 28 commits into from
Mar 30, 2024
Merged

fix: fix the scope of recover() #1672

merged 28 commits into from
Mar 30, 2024

Conversation

deelawn
Copy link
Contributor

@deelawn deelawn commented Feb 21, 2024

High level overview

Addresses #1656. This is meant to bring achieve parity between gno and go's recover functionality. The new tests help to ensure this.

BREAKING CHANGE: this will break any realm code that has relies on the incorrect recover implementation

Changes

For the convenience of the reviewer, here are the categories of changes that have been made:

  • the recover function has been modified to determine whether a panic can be recovered; this is based on both the "level" of nested defer statements and the frame from which the panic was initiated
  • Frames are now stored as pointers to avoid copying frame values as they are tracked by the Exceptions that have been thrown
  • a new Exception type has been defined to encapsulate both the panic string and the frame in which it was initiated
  • the machine has two new "scope" member variables for tracking levels of panic and defer
  • added safety mechanisms to retrieving frames because we may not always want it to panic when trying to retrieve a call frame at an index that exceeds the stack depth
  • the gno standard library's testing package's Recover function no longer works as intended; the tests have been modified to achieve the intended behavior
  • various new file tests have been added to ensure recover behaves as expected in certain edge cases
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@deelawn deelawn changed the title Fix the scope of recover() fix: fix the scope of recover() Feb 21, 2024
@deelawn deelawn linked an issue Feb 21, 2024 that may be closed by this pull request
@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Feb 22, 2024
Copy link

codecov bot commented Feb 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.60%. Comparing base (6afab42) to head (0571ff5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1672      +/-   ##
==========================================
+ Coverage   44.84%   47.60%   +2.75%     
==========================================
  Files         459      389      -70     
  Lines       67625    61641    -5984     
==========================================
- Hits        30329    29344     -985     
+ Misses      34756    29846    -4910     
+ Partials     2540     2451      -89     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@deelawn deelawn marked this pull request as ready for review February 23, 2024 04:13
gnovm/cmd/gno/testdata/gno_test/recover.txtar Show resolved Hide resolved
gnovm/pkg/gnolang/machine.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/machine.go Show resolved Hide resolved
@deelawn deelawn marked this pull request as draft February 27, 2024 18:15
@deelawn
Copy link
Contributor Author

deelawn commented Feb 27, 2024

converted to draft while I address some issues brought up in the comments

@deelawn deelawn marked this pull request as ready for review February 27, 2024 20:31
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Looks good 💯

Thank you for resolving this issue 🙏

I've pinged @petar-dambovaliev to give another sanity check, otherwise we're good to go

gnovm/pkg/gnolang/machine.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/machine.go Show resolved Hide resolved
gnovm/pkg/gnolang/frame.go Outdated Show resolved Hide resolved
@deelawn deelawn merged commit d79930c into gnolang:master Mar 30, 2024
190 of 191 checks passed
@deelawn deelawn deleted the bug/recover branch March 30, 2024 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Status: 🚀 Needed for Launch
Status: Done
Development

Successfully merging this pull request may close these issues.

recover() does not behave as expected
4 participants