diff --git a/client/config.go b/client/config.go index beb14cb0..6edb08bf 100644 --- a/client/config.go +++ b/client/config.go @@ -23,7 +23,13 @@ func InitConfig(cmd *cobra.Command) error { } configFile := path.Join(home, "config", "config.toml") - if _, err := os.Stat(configFile); err == nil { + _, err = os.Stat(configFile) + if err != nil && !os.IsNotExist(err) { + // Immediately return if the error isn't related to the file not existing. + // See issue https://github.com/tharsis/ethermint/issues/539 + return err + } + if err == nil { viper.SetConfigFile(configFile) if err := viper.ReadInConfig(); err != nil { diff --git a/client/config_test.go b/client/config_test.go new file mode 100644 index 00000000..0f4625dc --- /dev/null +++ b/client/config_test.go @@ -0,0 +1,27 @@ +package client + +import ( + "os" + "path/filepath" + "testing" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" +) + +func TestInitConfigNonNotExistError(t *testing.T) { + tempDir := t.TempDir() + subDir := filepath.Join(tempDir, "nonPerms") + if err := os.Mkdir(subDir, 0600); err != nil { + t.Fatalf("Failed to create sub directory: %v", err) + } + cmd := &cobra.Command{} + cmd.PersistentFlags().String(flags.FlagHome, "", "") + if err := cmd.PersistentFlags().Set(flags.FlagHome, subDir); err != nil { + t.Fatalf("Could not set home flag [%T] %v", err, err) + } + + if err := InitConfig(cmd); !os.IsPermission(err) { + t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err) + } +}