mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-21 16:05:02 +02:00
Improve stack trace formatting
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -251,11 +251,20 @@ func (self *Loop) DebugPrintln(args ...any) {
|
||||
func (self *Loop) Run() (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
stack := utils.Splitlines(string(debug.Stack()))
|
||||
pcs := make([]uintptr, 256)
|
||||
n := runtime.Callers(2, pcs)
|
||||
frames := runtime.CallersFrames(pcs[:n])
|
||||
err = fmt.Errorf("Paniced: %s", r)
|
||||
fmt.Fprintf(os.Stderr, "\r\nPaniced with error: %s\r\nStacktrace:\r\n", r)
|
||||
for _, line := range stack {
|
||||
fmt.Fprintf(os.Stderr, "%s\r\n", line)
|
||||
fmt.Fprintf(os.Stderr, "\r\nPaniced with error: %s\r\nStacktrace (most recent call first):\r\n", r)
|
||||
found_first_frame := false
|
||||
for frame, more := frames.Next(); more; frame, more = frames.Next() {
|
||||
if !found_first_frame {
|
||||
if strings.HasPrefix(frame.Function, "runtime.") {
|
||||
continue
|
||||
}
|
||||
found_first_frame = true
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "%s\r\n\t%s:%d\r\n", frame.Function, frame.File, frame.Line)
|
||||
}
|
||||
if self.terminal_options.alternate_screen {
|
||||
term, err := tty.OpenControllingTerm(tty.SetRaw)
|
||||
|
||||
Reference in New Issue
Block a user