Skip to content

Commit

Permalink
fix(pkg/errors): correct stacktraces for inlined functions (gnolang#901)
Browse files Browse the repository at this point in the history
* fix(pkg/errors): correct stacktraces for inlined functions

* refactor

---------

Co-authored-by: Manfred Touron <[email protected]>
  • Loading branch information
2 people authored and Doozers committed Aug 31, 2023
1 parent fffec6e commit 5a64ab4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tm2/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ func (err *cmnError) Format(s fmt.State, verb rune) {
// Write stack trace.
if err.stacktrace != nil {
s.Write([]byte("Stack Trace:\n"))
for i, pc := range err.stacktrace {
fnc := runtime.FuncForPC(pc)
file, line := fnc.FileLine(pc)
fmt.Fprintf(s, " %4d %s:%d\n", i, file, line)
frames := runtime.CallersFrames(err.stacktrace)
for i := 0; ; i++ {
frame, more := frames.Next()
fmt.Fprintf(s, " %4d %s:%d\n", i, frame.File, frame.Line)
if !more {
break
}
}
}
s.Write([]byte("--= /Error =--\n"))
Expand Down

0 comments on commit 5a64ab4

Please sign in to comment.