From d4a92adc65034afe0da022b86209c75086ddfbcb Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 2 Nov 2020 23:20:06 +0000 Subject: [PATCH] add rough error logging for read/write errors --- api.go | 5 ++++- common/common.go | 12 +++++++----- storage.go | 7 +++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/api.go b/api.go index cff593f..7d00f2e 100644 --- a/api.go +++ b/api.go @@ -207,7 +207,10 @@ func (app *appContext) getOmbiUser(jfID string) (map[string]interface{}, int, er return nil, code, err } username := jfUser["Name"].(string) - email := app.storage.emails[jfID].(string) + email := "" + if e, ok := app.storage.emails[jfID]; ok { + email := e.(string) + } for _, ombiUser := range ombiUsers { ombiAddr := "" if a, ok := ombiUser["emailAddress"]; ok && a != nil { diff --git a/common/common.go b/common/common.go index 43b09c3..ed94ad1 100644 --- a/common/common.go +++ b/common/common.go @@ -11,11 +11,13 @@ type TimeoutHandler func() // NewTimeoutHandler returns a new Timeout handler. func NewTimeoutHandler(name, addr string, noFail bool) TimeoutHandler { return func() { - out := fmt.Sprintf("Failed to authenticate with %s @ %s: Timed out", name, addr) - if noFail { - log.Print(out) - } else { - log.Fatalf(out) + if r := recover(); r != nil { + out := fmt.Sprintf("Failed to authenticate with %s @ %s: Timed out", name, addr) + if noFail { + log.Print(out) + } else { + log.Fatalf(out) + } } } } diff --git a/storage.go b/storage.go index becda9a..b8aab62 100644 --- a/storage.go +++ b/storage.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "io/ioutil" + "log" "strconv" "time" ) @@ -172,6 +173,9 @@ func loadJSON(path string, obj interface{}) error { file = []byte("{}") } err = json.Unmarshal(file, &obj) + if err != nil { + log.Printf("ERROR: Failed to read \"%s\": %s", path, err) + } return err } @@ -181,5 +185,8 @@ func storeJSON(path string, obj interface{}) error { return err } err = ioutil.WriteFile(path, data, 0644) + if err != nil { + log.Printf("ERROR: Failed to write to \"%s\": %s", path, err) + } return err }