Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Nov 18, 2024
1 parent c603537 commit 2f65631
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 65 deletions.
7 changes: 3 additions & 4 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
goio "io"
"log"
"math"
Expand Down Expand Up @@ -167,12 +166,12 @@ type proxyWriter struct {

// tee temporarily appends the writer w to an underlying MultiWriter, which
// should then be reverted using revert().
func (p *proxyWriter) tee(w io.Writer) (revert func()) {
func (p *proxyWriter) tee(w goio.Writer) (revert func()) {
save := p.Writer
if save == io.Discard {
if save == goio.Discard {
p.Writer = w
} else {
p.Writer = io.MultiWriter(save, w)
p.Writer = goio.MultiWriter(save, w)
}
return func() {
p.Writer = save
Expand Down
52 changes: 0 additions & 52 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,58 +435,6 @@ func (m *Machine) Stacktrace() (stacktrace Stacktrace) {
return
}

// in case of panic, inject location information to exception.
func (m *Machine) injectLocOnPanic() {
if r := recover(); r != nil {
// Show last location information.
// First, determine the line number of expression or statement if any.
lastLine := 0
lastColumn := 0
if len(m.Exprs) > 0 {
for i := len(m.Exprs) - 1; i >= 0; i-- {
expr := m.Exprs[i]
if expr.GetLine() > 0 {
lastLine = expr.GetLine()
lastColumn = expr.GetColumn()
break
}
}
}
if lastLine == 0 && len(m.Stmts) > 0 {
for i := len(m.Stmts) - 1; i >= 0; i-- {
stmt := m.Stmts[i]
if stmt.GetLine() > 0 {
lastLine = stmt.GetLine()
lastColumn = stmt.GetColumn()
break
}
}
}
// Append line number to block location.
lastLoc := Location{}
for i := len(m.Blocks) - 1; i >= 0; i-- {
block := m.Blocks[i]
src := block.GetSource(m.Store)
loc := src.GetLocation()
if !loc.IsZero() {
lastLoc = loc
if lastLine > 0 {
lastLoc.Line = lastLine
lastLoc.Column = lastColumn
}
break
}
}
// wrap panic with location information.
if !lastLoc.IsZero() {
fmt.Printf("%s: %v\n", lastLoc.String(), r)
panic(errors.Wrap(r, fmt.Sprintf("location: %s", lastLoc.String())))
} else {
panic(r)
}
}
}

// Convenience for tests.
// Production must not use this, because realm package init
// must happen after persistence and realm finalization,
Expand Down
3 changes: 1 addition & 2 deletions gnovm/pkg/test/filetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ func (opts *FileTestOptions) runTest(m *gno.Machine, pkgPath, filename string, c
pv2 := m.Store.GetPackage(pkgPath, false)
m.SetActivePackage(pv2)
gno.EnableDebug()
// clear store.opslog from init function(s),
// and PreprocessAllFilesAndSaveBlockNodes().
// clear store.opslog from init function(s).
m.Store.SetLogStoreOps(true) // resets.
m.RunStatement(gno.S(gno.Call(gno.X("main"))))
}
Expand Down
14 changes: 7 additions & 7 deletions gnovm/pkg/test/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ func loadStdlib(rootDir, pkgPath string, store gno.Store, stdout io.Writer) (*gn
return m2.RunMemPackageWithOverrides(memPkg, true)
}

type errorWithStack struct {
type stackWrappedError struct {
err error
stack []byte
}

func (e *errorWithStack) Error() string { return e.err.Error() }
func (e *errorWithStack) Unwrap() error { return e.err }
func (e *errorWithStack) String() string {
func (e *stackWrappedError) Error() string { return e.err.Error() }
func (e *stackWrappedError) Unwrap() error { return e.err }
func (e *stackWrappedError) String() string {
return fmt.Sprintf("%v\nstack:\n%v", e.err, string(e.stack))
}

Expand All @@ -234,9 +234,9 @@ func LoadImports(store gno.Store, filename string, content []byte) (err error) {
case gno.UnhandledPanicError:
err = v
case error:
err = &errorWithStack{v, debug.Stack()}
err = &stackWrappedError{v, debug.Stack()}
default:
err = &errorWithStack{fmt.Errorf("%v", v), debug.Stack()}
err = &stackWrappedError{fmt.Errorf("%v", v), debug.Stack()}
}
}
}()
Expand All @@ -257,7 +257,7 @@ func LoadImports(store gno.Store, filename string, content []byte) (err error) {
}
pkg := store.GetPackage(impPath, true)
if pkg == nil {
return fmt.Errorf("package not found: %v", impPath)
return fmt.Errorf("unknown import path %v", impPath)
}
}
return nil
Expand Down

0 comments on commit 2f65631

Please sign in to comment.