mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-15 13:04:38 +02:00
Move error handling code into its own library
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/kovidgoyal/go-parallel"
|
||||
"github.com/kovidgoyal/kitty/tools/disk_cache"
|
||||
"github.com/kovidgoyal/kitty/tools/icons"
|
||||
"github.com/kovidgoyal/kitty/tools/utils"
|
||||
@@ -114,8 +115,7 @@ func (p *ImagePreview) ensure_source_image() (err error) {
|
||||
func (p *ImagePreview) render_image(h *Handler, x, y, width, height int) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
text, _ := utils.Format_stacktrace_on_panic(r)
|
||||
h.err_chan <- fmt.Errorf("%s", text)
|
||||
h.err_chan <- parallel.Format_stacktrace_on_panic(r, 1)
|
||||
p.WakeupMainThread()
|
||||
}
|
||||
}()
|
||||
@@ -160,8 +160,7 @@ func (p *ImagePreview) Render(h *Handler, x, y, width, height int) {
|
||||
func (p *ImagePreview) start_rendering() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
text, _ := utils.Format_stacktrace_on_panic(r)
|
||||
p.render_channel <- render_data{err: fmt.Errorf("%s", text)}
|
||||
p.render_channel <- render_data{err: parallel.Format_stacktrace_on_panic(r, 1)}
|
||||
}
|
||||
close(p.render_channel)
|
||||
p.WakeupMainThread()
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/kovidgoyal/go-parallel"
|
||||
"github.com/kovidgoyal/kitty/tools/highlight"
|
||||
"github.com/kovidgoyal/kitty/tools/icons"
|
||||
"github.com/kovidgoyal/kitty/tools/tui/loop"
|
||||
@@ -261,8 +262,8 @@ func (pm *PreviewManager) highlight_file_async(path string, output chan highligh
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
text, _ := utils.Format_stacktrace_on_panic(r)
|
||||
debugprintln(fmt.Sprintf("Failed to highlight: %s with panic: %s", path, text))
|
||||
err := parallel.Format_stacktrace_on_panic(r, 1)
|
||||
debugprintln(fmt.Sprintf("Failed to highlight: %s with panic: %s", path, err))
|
||||
}
|
||||
close(output)
|
||||
pm.WakeupMainThread()
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kovidgoyal/go-parallel"
|
||||
"github.com/kovidgoyal/kitty/tools/cli"
|
||||
"github.com/kovidgoyal/kitty/tools/tui/loop"
|
||||
"github.com/kovidgoyal/kitty/tools/utils"
|
||||
@@ -26,8 +27,7 @@ func FilePromptCompleter(getcwd func() string) func(string, string) *cli.Complet
|
||||
return func(before_cursor, after_cursor string) (ans *cli.Completions) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
text, err := utils.Format_stacktrace_on_panic(r)
|
||||
debugprintln(text)
|
||||
err := parallel.Format_stacktrace_on_panic(r, 1)
|
||||
debugprintln(err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/kovidgoyal/go-parallel"
|
||||
"github.com/kovidgoyal/kitty/tools/fzf"
|
||||
"github.com/kovidgoyal/kitty/tools/ignorefiles"
|
||||
"github.com/kovidgoyal/kitty/tools/utils"
|
||||
@@ -219,8 +220,8 @@ func (fss *FileSystemScanner) worker() {
|
||||
defer fss.unlock()
|
||||
fss.in_progress.Store(false)
|
||||
if r := recover(); r != nil {
|
||||
st, qerr := utils.Format_stacktrace_on_panic(r)
|
||||
fss.err = fmt.Errorf("%w\n%s", qerr, st)
|
||||
qerr := parallel.Format_stacktrace_on_panic(r, 1)
|
||||
fss.err = qerr
|
||||
}
|
||||
for _, l := range fss.listeners {
|
||||
close(l)
|
||||
@@ -532,8 +533,8 @@ func (fss *FileSystemScorer) worker(on_results chan bool, worker_wait *sync.Wait
|
||||
defer worker_wait.Done()
|
||||
if r := recover(); r != nil {
|
||||
if fss.keep_going.Load() {
|
||||
st, qerr := utils.Format_stacktrace_on_panic(r)
|
||||
fss.on_results(fmt.Errorf("%w\n%s", qerr, st), true)
|
||||
qerr := parallel.Format_stacktrace_on_panic(r, 1)
|
||||
fss.on_results(qerr, true)
|
||||
}
|
||||
} else {
|
||||
if fss.keep_going.Load() {
|
||||
|
||||
Reference in New Issue
Block a user