Skip to content

Commit

Permalink
chore: rename RealmUnhandledPanicException type to `UnhandledPanicE…
Browse files Browse the repository at this point in the history
…rror` and change its `String()` method to `Error()`
  • Loading branch information
omarsy committed Aug 1, 2024
1 parent d3f6b4a commit 778965e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) {
switch r := r.(type) {
case store.OutOfGasException: // panic in consumeGas()
panic(r)
case gno.RealmUnhandledPanicException:
err = errors.Wrap(fmt.Errorf("%v", r), "VM call panic: %s\nStacktrace: %s\n",
r.Descriptor, m.ExceptionsStacktrace())
case gno.UnhandledPanicError:
err = errors.Wrap(fmt.Errorf("%v", r.Error()), "VM call panic: %s\nStacktrace: %s\n",
r.Error(), m.ExceptionsStacktrace())
default:
err = errors.Wrap(fmt.Errorf("%v", r), "VM call panic: %v\nMachine State:%s\nStacktrace: %s\n",
r, m.String(), m.Stacktrace().String())
Expand Down
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ func runExpr(m *gno.Machine, expr string) {
defer func() {
if r := recover(); r != nil {
switch r := r.(type) {
case gno.RealmUnhandledPanicException:
case gno.UnhandledPanicError:
fmt.Printf("panic running expression %s: %v\nStacktrace: %s\n",
expr, r, m.ExceptionsStacktrace())
expr, r.Error(), m.ExceptionsStacktrace())

Check warning on line 194 in gnovm/cmd/gno/run.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/run.go#L192-L194

Added lines #L192 - L194 were not covered by tests
default:
fmt.Printf("panic running expression %s: %v\nMachine State:%s\nStacktrace: %s\n",
expr, r, m.String(), m.Stacktrace().String())
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func evalTest(debugAddr, in, file string) (out, err, stacktrace string) {
defer func() {
if r := recover(); r != nil {
switch r.(type) {
case gnolang.RealmUnhandledPanicException:
case gnolang.UnhandledPanicError:
stacktrace = m.ExceptionsStacktrace()
default:
stacktrace = m.Stacktrace().String()
Expand Down
18 changes: 9 additions & 9 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (e Exception) Sprint(m *Machine) string {
return e.Value.Sprint(m)
}

// RealmUnhandledPanicException represents an error thrown when a panic is not handled in the realm.
type RealmUnhandledPanicException struct {
// UnhandledPanicError represents an error thrown when a panic is not handled in the realm.
type UnhandledPanicError struct {
Descriptor string // Description of the unhandled panic.
}

func (e RealmUnhandledPanicException) String() string {
func (e UnhandledPanicError) Error() string {
return e.Descriptor
}

Expand Down Expand Up @@ -785,9 +785,9 @@ func (m *Machine) RunFunc(fn Name) {
defer func() {
if r := recover(); r != nil {
switch r := r.(type) {
case RealmUnhandledPanicException:
fmt.Printf("Machine.RunFunc(%q) panic: %v\nStacktrace: %s\n",
fn, r.Descriptor, m.ExceptionsStacktrace())
case UnhandledPanicError:
fmt.Printf("Machine.RunFunc(%q) panic: %s\nStacktrace: %s\n",
fn, r.Error(), m.ExceptionsStacktrace())
default:
fmt.Printf("Machine.RunFunc(%q) panic: %v\nMachine State:%s\nStacktrace: %s\n",
fn, r, m.String(), m.Stacktrace().String())

Check warning on line 793 in gnovm/pkg/gnolang/machine.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/machine.go#L787-L793

Added lines #L787 - L793 were not covered by tests
Expand All @@ -802,9 +802,9 @@ func (m *Machine) RunMain() {
defer func() {
if r := recover(); r != nil {
switch r := r.(type) {
case RealmUnhandledPanicException:
fmt.Printf("Machine.RunMain() panic: %v\nStacktrace: %s\n",
r.Descriptor, m.ExceptionsStacktrace())
case UnhandledPanicError:
fmt.Printf("Machine.RunMain() panic: %s\nStacktrace: %s\n",
r.Error(), m.ExceptionsStacktrace())
default:
fmt.Printf("Machine.RunMain() panic: %v\nMachine State:%s\nStacktrace: %s\n",
r, m.String(), m.Stacktrace())

Check warning on line 810 in gnovm/pkg/gnolang/machine.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/machine.go#L808-L810

Added lines #L808 - L810 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/op_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (m *Machine) doOpPanic2() {
for i, ex := range m.Exceptions {
exs[i] = ex.Sprint(m)
}
panic(RealmUnhandledPanicException{
panic(UnhandledPanicError{
Descriptor: strings.Join(exs, "\n\t"),
})
}
Expand Down
6 changes: 3 additions & 3 deletions gnovm/tests/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
errstr = v.Sprint(m)
case *gno.PreprocessError:
errstr = v.Unwrap().Error()
case gno.RealmUnhandledPanicException:
errstr = v.Descriptor
case gno.UnhandledPanicError:
errstr = v.Error()
default:
errstr = strings.TrimSpace(fmt.Sprintf("%v", pnc))
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
var stacktrace string

switch pnc.(type) {
case gno.RealmUnhandledPanicException:
case gno.UnhandledPanicError:
stacktrace = m.ExceptionsStacktrace()
default:
stacktrace = m.Stacktrace().String()
Expand Down

0 comments on commit 778965e

Please sign in to comment.