fix a panic and handle cleaning up after a panic
This commit is contained in:
parent
c2d2fe25c0
commit
4f4758f7fe
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"git.yetaga.in/alazyreader/library/book"
|
"git.yetaga.in/alazyreader/library/book"
|
||||||
@ -116,6 +117,19 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
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)
|
l := ui.NewList(Titles(state.Get("library").([]book.Book)), 0)
|
||||||
menu := ui.NewBox(
|
menu := ui.NewBox(
|
||||||
|
@ -6,4 +6,5 @@ type Config struct {
|
|||||||
DBHost string
|
DBHost string
|
||||||
DBPort string
|
DBPort string
|
||||||
DBName string
|
DBName string
|
||||||
|
Debug bool
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user