Browse Source

fix a panic and handle cleaning up after a panic

pull/1/head
David Ashby 2 months ago
parent
commit
4f4758f7fe
  1. 14
      cmd/manage/main.go
  2. 1
      config/config.go
  3. 3
      ui/ui.go

14
cmd/manage/main.go

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"runtime/debug"
"sync"
"git.yetaga.in/alazyreader/library/book"
@ -116,6 +117,19 @@ func main() {
if err != nil {
log.Fatalln(err)
}
// cleanup our screen and log if we panic and crash out somewhere
defer func() {
if r := recover(); r != nil {
if screen != nil {
screen.Fini()
}
fmt.Println("fatal panic;", r)
if c.Debug {
fmt.Println("stacktrace: \n" + string(debug.Stack()))
}
return
}
}()
l := ui.NewList(Titles(state.Get("library").([]book.Book)), 0)
menu := ui.NewBox(

1
config/config.go

@ -6,4 +6,5 @@ type Config struct {
DBHost string
DBPort string
DBName string
Debug bool
}

3
ui/ui.go

@ -296,6 +296,9 @@ func (l *List) Selected() int {
}
func (l *List) SelectedID() int {
if l.listItems == nil || len(l.listItems) == 0 {
return 0
}
return l.listItems[l.selected].Key
}

Loading…
Cancel
Save