From d7b53d74c59fd8ce18cc7f8afd9466f1b4d28aa1 Mon Sep 17 00:00:00 2001 From: isthisnagee Date: Fri, 21 Jan 2022 23:24:39 -0800 Subject: [PATCH] Return error from NewApp Floating up the error seems like a best practice. Part of https://git.nagee.dev/isthisnagee/diary/issues/7 --- cmd/util.go | 6 ++++-- model/entry.go | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/util.go b/cmd/util.go index 7182910..e1789a7 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -65,8 +65,10 @@ func InitApp() { cobra.CheckErr(err) } - var app = model.NewApp(cfg.DbPath) - App = &TApp{&app, &cfg} + var app, err = model.NewApp(cfg.DbPath) + cobra.CheckErr(err) + + App = &TApp{app, &cfg} } var fmt_str = "%-10s %-20s %s\n" diff --git a/model/entry.go b/model/entry.go index 1265485..862eb37 100644 --- a/model/entry.go +++ b/model/entry.go @@ -20,12 +20,12 @@ type App struct { *db.DbCtx } -func NewApp(db_path string) App { +func NewApp(db_path string) (*App, error) { app, err := db.Init(db_path) if err != nil { - log.Fatal(err.Error()) + return nil, err } - return App{app} + return &App{app}, nil }