mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 14:49:27 +08:00
fix(recovery): track line number to avoid showing stale source in stack trace
This commit is contained in:
parent
5260de6a83
commit
51b00a3ac7
@ -118,6 +118,7 @@ func stack(skip int) []byte {
|
||||
var (
|
||||
nLine string
|
||||
lastFile string
|
||||
lastLine int
|
||||
err error
|
||||
)
|
||||
for i := skip; ; i++ { // Skip the expected number of frames
|
||||
@ -127,12 +128,13 @@ func stack(skip int) []byte {
|
||||
}
|
||||
// Print this much at least. If we can't find the source, it won't show.
|
||||
fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc)
|
||||
if file != lastFile {
|
||||
if file != lastFile || line != lastLine {
|
||||
nLine, err = readNthLine(file, line-1)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
lastFile = file
|
||||
lastLine = line
|
||||
}
|
||||
fmt.Fprintf(buf, "\t%s: %s\n", function(pc), cmp.Or(nLine, dunno))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user