From 1bfec54c9309a03f3c6c7ea8fac07f9faa32bb66 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Wed, 25 Aug 2021 18:10:06 +0100 Subject: [PATCH] print error and include in txt log on crash; fix email migration --- exit.go | 4 ++++ migrations.go | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/exit.go b/exit.go index 251189f..ddf5709 100644 --- a/exit.go +++ b/exit.go @@ -50,6 +50,10 @@ func Exit(err interface{}) { log.Fatalf("Failed to load template: %v", err) } logCache := lineCache.String() + if err != nil { + fmt.Println(err) + logCache += "\n" + fmt.Sprint(err) + } logCache += "\n" + string(debug.Stack()) sanitized := sanitizeLog(logCache) data := map[string]interface{}{ diff --git a/migrations.go b/migrations.go index 674718f..d1627a9 100644 --- a/migrations.go +++ b/migrations.go @@ -90,11 +90,27 @@ func migrateEmailStorage(app *appContext) error { } newEmails := map[string]EmailAddress{} for jfID, addr := range emails { - newEmails[jfID] = EmailAddress{ - Addr: addr.(string), - Contact: true, + switch addr.(type) { + case string: + newEmails[jfID] = EmailAddress{ + Addr: addr.(string), + Contact: true, + } + // In case email settings still persist after migration has already happened + case map[string]interface{}: + return nil + default: + return fmt.Errorf("Email address was type %T, not string: \"%+v\"\n", addr, addr) } } + config, err := ini.Load(app.configPath) + if err != nil { + return err + } + config.Section("email").Key("use_24h").SetValue("") + if err := config.SaveTo(app.configPath); err != nil { + return err + } err = storeJSON(app.storage.emails_path+".bak", emails) if err != nil { return err