Merge pull request #11 from aerth/invalid-db

handle non-bolt files with a simple error screen
This commit is contained in:
Brian Buller 2017-04-05 07:07:06 -05:00 committed by GitHub
commit 6b6a241245
2 changed files with 14 additions and 3 deletions

View File

@ -32,7 +32,6 @@ func main() {
panic(err)
}
defer termbox.Close()
style := defaultStyle()
termbox.SetOutputMode(termbox.Output256)
@ -41,8 +40,14 @@ func main() {
currentFilename = databaseFile
db, err = bolt.Open(databaseFile, 0600, nil)
if err != nil {
fmt.Printf("Error reading file: %q\n", err.Error())
os.Exit(1)
if len(databaseFiles) > 1 {
mainLoop(nil, style)
continue
} else {
termbox.Close()
fmt.Printf("Error reading file: %q\n", err.Error())
os.Exit(111)
}
}
// First things first, load the database into memory

View File

@ -454,6 +454,12 @@ func (screen *BrowserScreen) moveCursorDown() bool {
func (screen *BrowserScreen) performLayout() {}
func (screen *BrowserScreen) drawScreen(style Style) {
if screen.db == nil {
screen.drawHeader(style)
screen.setMessage("Invalid DB. Press 'q' to quit, '?' for help")
screen.drawFooter(style)
return
}
if len(screen.db.buckets) == 0 && screen.mode&modeInsertBucket != modeInsertBucket {
// Force a bucket insert
screen.startInsertItemAtParent(typeBucket)