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:
parent
27e9c0d68b
commit
a67c887554
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user