From 6da9e7a17d5e056692b9d6e06e880f868cb78fb6 Mon Sep 17 00:00:00 2001 From: Gapodo Date: Sat, 25 Nov 2023 20:57:27 +0100 Subject: [PATCH] handle unknown home gracefully --- pkg/configuration/configuration.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/configuration/configuration.go b/pkg/configuration/configuration.go index 0e8c401..128ca94 100644 --- a/pkg/configuration/configuration.go +++ b/pkg/configuration/configuration.go @@ -10,7 +10,6 @@ import ( "git.kle.li/tools/go-import-redirector/pkg/configuration/file" "git.kle.li/tools/go-import-redirector/pkg/packagelist" "github.com/fsnotify/fsnotify" - "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -33,9 +32,12 @@ func New(cfgFile string, hotReload bool, reloadFunction func()) *Configuration { } else { // Find home directory. home, err := os.UserHomeDir() - cobra.CheckErr(err) + if err == nil { + c.v.AddConfigPath(home) + } else { + fmt.Println("Unable to determine $HOME, not searching it for potential config") + } - c.v.AddConfigPath(home) c.v.AddConfigPath("/etc/") c.v.AddConfigPath(".") c.v.SetConfigType("yaml")