fix a panic and handle cleaning up after a panic
This commit is contained in:
		@@ -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(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user