From 2c86ee671124165f20fc4bd5da276aa2511377e4 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 23 Jan 2025 18:51:26 +0100 Subject: [PATCH] refactor(gnolang): move Exception to frame.go --- gnovm/pkg/gnolang/frame.go | 27 +++++++++++++++++++++++++++ gnovm/pkg/gnolang/machine.go | 24 ------------------------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/gnovm/pkg/gnolang/frame.go b/gnovm/pkg/gnolang/frame.go index 60f19979b7a..bfd0d42229e 100644 --- a/gnovm/pkg/gnolang/frame.go +++ b/gnovm/pkg/gnolang/frame.go @@ -216,3 +216,30 @@ func toConstExpTrace(cte *ConstExpr) string { return tv.T.String() } + +//---------------------------------------- +// Exception + +// Exception represents a panic that originates from a gno program. +type Exception struct { + // Value is the value passed to panic. + Value TypedValue + // Frame is used to reference the frame a panic occurred in so that recover() knows if the + // currently executing deferred function is able to recover from the panic. + Frame *Frame + + Stacktrace Stacktrace +} + +func (e Exception) Sprint(m *Machine) string { + return e.Value.Sprint(m) +} + +// 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 UnhandledPanicError) Error() string { + return e.Descriptor +} diff --git a/gnovm/pkg/gnolang/machine.go b/gnovm/pkg/gnolang/machine.go index 75d12ac5402..4638312461f 100644 --- a/gnovm/pkg/gnolang/machine.go +++ b/gnovm/pkg/gnolang/machine.go @@ -18,30 +18,6 @@ import ( "github.com/gnolang/gno/tm2/pkg/store" ) -// Exception represents a panic that originates from a gno program. -type Exception struct { - // Value is the value passed to panic. - Value TypedValue - // Frame is used to reference the frame a panic occurred in so that recover() knows if the - // currently executing deferred function is able to recover from the panic. - Frame *Frame - - Stacktrace Stacktrace -} - -func (e Exception) Sprint(m *Machine) string { - return e.Value.Sprint(m) -} - -// 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 UnhandledPanicError) Error() string { - return e.Descriptor -} - //---------------------------------------- // Machine