1
1
mirror of https://github.com/walles/moar.git synced 2024-11-22 11:45:50 +03:00

Include stack trace in panic logs

This commit is contained in:
Johan Walles 2024-08-12 21:47:46 +02:00
parent 27e9c0d68b
commit a67c887554
9 changed files with 22 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package m
import (
"fmt"
"regexp"
"runtime/debug"
"strings"
"time"
@ -323,7 +324,7 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
go func() {
defer func() {
panicHandler("StartPaging()/moreLinesAvailable", recover())
panicHandler("StartPaging()/moreLinesAvailable", recover(), debug.Stack())
}()
for range p.reader.moreLinesAdded {
@ -342,7 +343,7 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
go func() {
defer func() {
panicHandler("StartPaging()/spinner", recover())
panicHandler("StartPaging()/spinner", recover(), debug.Stack())
}()
// Spin the spinner as long as contents is still loading
@ -368,7 +369,7 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
go func() {
defer func() {
panicHandler("StartPaging()/maybeDone", recover())
panicHandler("StartPaging()/maybeDone", recover(), debug.Stack())
}()
for range p.reader.maybeDone {

View File

@ -6,12 +6,13 @@ import (
log "github.com/sirupsen/logrus"
)
func panicHandler(goroutineName string, recoverResult any) {
func panicHandler(goroutineName string, recoverResult any, stackTrace []byte) {
if recoverResult == nil {
return
}
log.WithFields(log.Fields{
"recoverResult": recoverResult,
"panic": recoverResult,
"stackTrace": string(stackTrace),
}).Error("Goroutine panicked: " + goroutineName)
}

View File

@ -7,6 +7,7 @@ import (
"io"
"os"
"path"
"runtime/debug"
"strings"
"sync"
"sync/atomic"
@ -366,7 +367,7 @@ func newReaderFromStream(reader io.Reader, originalFileName *string, formatter c
go func() {
defer func() {
panicHandler("newReaderFromStream()/readStream()", recover())
panicHandler("newReaderFromStream()/readStream()", recover(), debug.Stack())
}()
returnMe.readStream(reader, formatter, lexer)

View File

@ -3,6 +3,7 @@ package m
import (
"fmt"
"runtime"
"runtime/debug"
"time"
log "github.com/sirupsen/logrus"
@ -125,7 +126,7 @@ func (p *Pager) findFirstHit(startPosition linenumbers.LineNumber, beforePositio
go func(i int, searchStart linenumbers.LineNumber, chunkBefore *linenumbers.LineNumber) {
defer func() {
panicHandler("findFirstHit()/chunkSearch", recover())
panicHandler("findFirstHit()/chunkSearch", recover(), debug.Stack())
}()
findings[i] <- p._findFirstHit(searchStart, chunkBefore, backwards)

View File

@ -6,12 +6,13 @@ import (
log "github.com/sirupsen/logrus"
)
func panicHandler(goroutineName string, recoverResult any) {
func panicHandler(goroutineName string, recoverResult any, stackTrace []byte) {
if recoverResult == nil {
return
}
log.WithFields(log.Fields{
"recoverResult": recoverResult,
"panic": recoverResult,
"stackTrace": string(stackTrace),
}).Error("Goroutine panicked: " + goroutineName)
}

View File

@ -7,6 +7,7 @@ import (
"io"
"os"
"os/signal"
"runtime/debug"
"sync/atomic"
"syscall"
@ -118,7 +119,7 @@ func (screen *UnixScreen) setupSigwinchNotification() {
signal.Notify(sigwinch, syscall.SIGWINCH)
go func() {
defer func() {
panicHandler("setupSigwinchNotification()/SIGWINCH", recover())
panicHandler("setupSigwinchNotification()/SIGWINCH", recover(), debug.Stack())
}()
for {

View File

@ -6,6 +6,7 @@ package twin
import (
"io"
"os"
"runtime/debug"
"testing"
"time"
@ -32,7 +33,7 @@ func TestInterruptableReader_blockedOnReadImmediate(t *testing.T) {
readResultChan := make(chan readResult)
go func() {
defer func() {
panicHandler("TestInterruptableReader_blockedOnReadImmediate()", recover())
panicHandler("TestInterruptableReader_blockedOnReadImmediate()", recover(), debug.Stack())
}()
buffer := make([]byte, 1)

View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"regexp"
"runtime/debug"
"strconv"
"strings"
"unicode/utf8"
@ -181,7 +182,7 @@ func NewScreenWithMouseModeAndColorCount(mouseMode MouseMode, terminalColorCount
go func() {
defer func() {
panicHandler("NewScreenWithMouseModeAndColorCount()/mainLoop()", recover())
panicHandler("NewScreenWithMouseModeAndColorCount()/mainLoop()", recover(), debug.Stack())
}()
screen.mainLoop()

View File

@ -3,6 +3,7 @@ package twin
import (
"io"
"os"
"runtime/debug"
"strings"
"testing"
"time"
@ -270,7 +271,7 @@ func TestInterruptableReader_blockedOnRead(t *testing.T) {
readResultChan := make(chan readResult)
go func() {
defer func() {
panicHandler("TestInterruptableReader_blockedOnRead()", recover())
panicHandler("TestInterruptableReader_blockedOnRead()", recover(), debug.Stack())
}()
buffer := make([]byte, 1)