-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gnovm): add stacktraces and log them in panic messages (#2145)
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:** ```go 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 ``` <details><summary>Contributors' checklist...</summary> - [ ] 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](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <git@howl.moe>
- Loading branch information
Showing
26 changed files
with
947 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# test panic | ||
|
||
loadpkg gno.land/r/demo/panic $WORK | ||
|
||
# start a new node | ||
gnoland start | ||
|
||
|
||
! gnokey maketx call -pkgpath gno.land/r/demo/panic --func Trigger --gas-fee 1000000ugnot --gas-wanted 2000000 --broadcast -chainid=tendermint_test test1 | ||
|
||
stderr 'p\<VPBlock\(3\,0\)\>\(\)' | ||
stderr 'gno.land/r/demo/panic/panic.gno:5' | ||
stderr 'pkg\<VPBlock\(1\,0\)\>\.Trigger\(\)' | ||
stderr 'gno.land/r/demo/panic/panic.gno:9' | ||
|
||
-- panic.gno -- | ||
package main | ||
|
||
func p() { | ||
i := "here" | ||
panic(i) | ||
} | ||
|
||
func Trigger() { | ||
p() | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.