From f6dedea101ea5f81448aac8af30302e2e13f621f Mon Sep 17 00:00:00 2001 From: Heinrich 'Henrik' Langos Date: Thu, 5 Jan 2023 12:27:42 +0000 Subject: [PATCH] fix(config): Always show config file name and abort if read fails (#46) With this change you should always know what config tube is using. If an explicitly requested file can not be read, then tube will complain and exit. This should fix issue #45 Reviewed-on: https://git.mills.io/prologic/tube/pulls/46 Co-authored-by: Heinrich 'Henrik' Langos Co-committed-by: Heinrich 'Henrik' Langos --- main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 0f9331f..d18e7dc 100644 --- a/main.go +++ b/main.go @@ -41,14 +41,15 @@ func main() { } cfg := app.DefaultConfig() + log.Infof("Reading configuration from %s", config) err := cfg.ReadFile(config) - if err == nil { - log.Infof("reading configuration from %s", config) - } else { - if !os.IsNotExist(err) { + if err != nil { + if flag.Lookup("config").Changed { log.Fatal(err) } + log.Infof("Reading %s failed. Starting with builtin defaults.", config) } + // I'd like to add something like this here: log.Debug("Active config: %s", cfg.toJson()) a, err := app.NewApp(cfg) if err != nil { log.Fatal(err)