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

feat(gnovm): add stacktraces and log them in panic messages #2145

Merged
merged 38 commits into from
Aug 2, 2024

Conversation

omarsy
Copy link
Member

@omarsy omarsy commented May 18, 2024

Closes #1812

Summary

This pull request introduces a new StackTrace mechanism to the Machine.Exceptions class, enhancing its exception handling capabilities by generating and appending detailed stacktraces during panic situations.

Panic Handling:

  • When a panic occurs, the current stack state is copied and appended to the exception details.
  • This includes the value of the panic, the last call frame, and the copied stack trace.

Code Example:

    package main

    func main() {
        f()
    }

    func f() {
        defer func() {
            panic("third")
        }()
        defer func() {
            panic("second")
        }()
        panic("first")
    }

Sample Output:

   Stacktrace:
       Exception 0: 
           panic((const ("first" <untyped> string)))
               main/files/panic0b.gno:14
           f<VPBlock(3,1)>()
               main/files/panic0b.gno:4
       Exception 1: 
           panic((const ("second" <untyped> string)))
               main/files/panic0b.gno:12
           f<VPBlock(3,1)>()
               main/files/panic0b.gno:4
       Exception 2: 
           panic((const ("third" <untyped> string)))
               main/files/panic0b.gno:9
           f<VPBlock(3,1)>()
               main/files/panic0b.gno:4
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.

@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels May 18, 2024
Copy link

codecov bot commented May 18, 2024

Codecov Report

Attention: Patch coverage is 82.92683% with 35 lines in your changes missing coverage. Please review.

Project coverage is 60.09%. Comparing base (5f28803) to head (778965e).
Report is 1 commits behind head on master.

Files Patch % Lines
gnovm/tests/file.go 55.26% 15 Missing and 2 partials ⚠️
gnovm/pkg/gnolang/machine.go 82.25% 11 Missing ⚠️
gnovm/pkg/gnolang/frame.go 95.50% 3 Missing and 1 partial ⚠️
gnovm/cmd/gno/run.go 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2145      +/-   ##
==========================================
- Coverage   60.14%   60.09%   -0.05%     
==========================================
  Files         560      560              
  Lines       74738    75035     +297     
==========================================
+ Hits        44950    45093     +143     
- Misses      26400    26556     +156     
+ Partials     3388     3386       -2     
Flag Coverage Δ
contribs/gnodev 60.58% <ø> (ø)
contribs/gnofaucet 15.31% <ø> (+0.85%) ⬆️
gno.land 64.18% <100.00%> (+0.02%) ⬆️
gnovm 64.13% <82.41%> (-0.15%) ⬇️
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (ø)
tm2 62.04% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@omarsy omarsy force-pushed the feat/1812 branch 7 times, most recently from b471ffc to 3d1fcae Compare May 20, 2024 23:12
@omarsy omarsy changed the title feat(#1812): add stack trace on machine feat(#1812): add Stacktrace Mechanism to Machine for Improved Exception Handling May 21, 2024
@omarsy omarsy marked this pull request as ready for review May 21, 2024 19:37
gnovm/pkg/gnolang/stack.go Outdated Show resolved Hide resolved
@leohhhn
Copy link
Contributor

leohhhn commented May 22, 2024

@omarsy

Thank you so much for this PR - this is super useful and is something that has been sitting on the backlog for way too long. I will make sure the team hears about this PR and takes a look as soon as possible.

@omarsy omarsy requested a review from thehowl July 22, 2024 18:20
@omarsy omarsy requested a review from deelawn July 23, 2024 18:58
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

Sorry; this should be the last round of review.

gnovm/pkg/gnolang/frame.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/frame.go Show resolved Hide resolved
gnovm/pkg/gnolang/machine.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/machine.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/machine.go Outdated Show resolved Hide resolved
@thehowl thehowl changed the title feat(#1812): add Stacktrace Mechanism to Machine for Improved Exception Handling feat(gnovm): add stacktraces and log them with panic messages Jul 24, 2024
@thehowl thehowl changed the title feat(gnovm): add stacktraces and log them with panic messages feat(gnovm): add stacktraces and log them in panic messages Jul 24, 2024
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

One last naming thing. Everything else LGTM. 👏 👏 👏 👏

gnovm/pkg/gnolang/machine.go Outdated Show resolved Hide resolved
…rror` and change its `String()` method to `Error()`
Copy link
Contributor

@piux2 piux2 left a comment

Choose a reason for hiding this comment

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

LGTM

@thehowl thehowl merged commit 56f8357 into gnolang:master Aug 2, 2024
115 checks passed
@omarsy omarsy deleted the feat/1812 branch August 3, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Add stacktrace functionality and replace (some) uses of Machine.String with it
6 participants