From 0a23fbd2ac02f78bf89c5c4eabe1a05518edfdf9 Mon Sep 17 00:00:00 2001 From: Grant Arnold Date: Thu, 30 Oct 2025 23:11:22 +0000 Subject: [PATCH 1/2] Move parse error checking to config file check function --- cmd/functions.go | 6 ++++++ cmd/root.go | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/functions.go b/cmd/functions.go index 62968b7..50d6837 100644 --- a/cmd/functions.go +++ b/cmd/functions.go @@ -175,6 +175,12 @@ func checkConfigFile(requireToken bool) error { if err != nil { return fmt.Errorf("could not open the config file " + viper.ConfigFileUsed() + ". Have you called the login command? ") } + // make sure the config file is parsable + err = viper.ReadInConfig() + if err != nil { + return fmt.Errorf("%w: could not parse the config file "+viper.ConfigFileUsed()+". Have you called the login command? ", err) + } + fmeflowUrl := viper.GetString("url") // check the fme server URL is valid diff --git a/cmd/root.go b/cmd/root.go index 91b4f7b..2196d17 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -102,10 +102,7 @@ func initConfig() { //viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. - err := viper.ReadInConfig() - if err != nil { // Handle errors reading the config file - cobra.CheckErr(err) - } + viper.ReadInConfig() } From 279dbaf4ae18fd69772c3981b974ec7b21f6ca93 Mon Sep 17 00:00:00 2001 From: Grant Arnold Date: Fri, 31 Oct 2025 16:35:01 +0000 Subject: [PATCH 2/2] Fix up tests so that we will catch initial login problems. --- cmd/login_v4_test.go | 1 + cmd/testFunctions.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/login_v4_test.go b/cmd/login_v4_test.go index 21bd63b..d470ddd 100644 --- a/cmd/login_v4_test.go +++ b/cmd/login_v4_test.go @@ -102,6 +102,7 @@ token: 5ba5e0fd15c2403bc8b2e3aa1dfb975ca2197fbe url: %s `, mainHttpServerLogin.URL), }, + omitConfig: true, }, { name: "login with token", diff --git a/cmd/testFunctions.go b/cmd/testFunctions.go index 4a9e00f..0e5b011 100644 --- a/cmd/testFunctions.go +++ b/cmd/testFunctions.go @@ -111,7 +111,7 @@ func runTests(tcs []testCase, t *testing.T) { } // if a config file isn't specified, generate a random file and set the config file flag - if !configFlagExists(tc.args) { + if !configFlagExists(tc.args) && !tc.omitConfig { f, err := os.CreateTemp("", "config-file*.yaml") require.NoError(t, err) defer os.Remove(f.Name()) // clean up