Skip to content

Commit

Permalink
change to use normal stacktraces
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Jan 15, 2024
1 parent a6a7141 commit cfd9737
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -443,8 +443,7 @@ func runTestFiles(
) (errs error) {
defer func() {
if r := recover(); r != nil {
trace := smallStacktrace()
errs = multierr.Append(fmt.Errorf("panic: %v\ngno machine: %v\nstracktrace:\n%v", r, m.String(), trace), errs)
errs = multierr.Append(fmt.Errorf("panic: %v\nstack:\n%v\ngno machine: %v", r, string(debug.Stack()), m.String()), errs)
}
}()

Expand Down Expand Up @@ -541,42 +540,6 @@ func runTestFiles(
return errs
}

/*
smallStacktrace sample result:
prog.go:11 main.main
proc.go:250 runtime.main
asm_amd64.s:1598 runtime.goexit
*/
func smallStacktrace() string {
const unicodeEllipsis = "\u2026"

var buf bytes.Buffer
pc := make([]uintptr, 100)
pc = pc[:runtime.Callers(2, pc)]
frames := runtime.CallersFrames(pc)
for {
f, more := frames.Next()

if idx := strings.LastIndexByte(f.Function, '/'); idx >= 0 {
f.Function = f.Function[idx+1:]
}

// trim full path to at most 30 characters
fullPath := fmt.Sprintf("%s:%-4d", f.File, f.Line)
if len(fullPath) > 30 {
fullPath = unicodeEllipsis + fullPath[len(fullPath)-29:]
}

fmt.Fprintf(&buf, "%30s %s\n", fullPath, f.Function)

if !more {
return buf.String()
}
}
return buf.String()
}

// mirror of stdlibs/testing.Report
type report struct {
Name string
Expand Down

0 comments on commit cfd9737

Please sign in to comment.