diff --git a/cmd/common/config.go b/cmd/common/config.go index 6a4b98fc51c..afbf642431b 100644 --- a/cmd/common/config.go +++ b/cmd/common/config.go @@ -42,7 +42,10 @@ func (c Config) ToFile(file string) error { if err := validateConfig(c); err != nil { return errors.Wrap(err, "config isn't valid") } - b, _ := yaml.Marshal(c) + b, err := yaml.Marshal(c) + if err != nil { + return errors.Wrap(err, "failed to marshal config") + } if err := os.WriteFile(file, b, 0o600); err != nil { return errors.Errorf("failed writing file %s: %v", file, err) } @@ -50,16 +53,17 @@ func (c Config) ToFile(file string) error { } func validateConfig(conf Config) error { - nonEmptyStrings := []string{ - conf.SignerConfig.MSPID, - conf.SignerConfig.IdentityPath, - conf.SignerConfig.KeyPath, + nonEmptyElems := map[string]string{ + "MSPID": conf.SignerConfig.MSPID, + "IdentityPath": conf.SignerConfig.IdentityPath, + "KeyPath": conf.SignerConfig.KeyPath, } - for _, s := range nonEmptyStrings { - if s == "" { - return errors.New("empty string that is mandatory") + for key, value := range nonEmptyElems { + if value == "" { + return errors.Errorf("%s is mandatory and cannot be empty", key) } } + return nil } diff --git a/cmd/discover/main_test.go b/cmd/discover/main_test.go index 55845f4bfef..bd7a8f5cb31 100644 --- a/cmd/discover/main_test.go +++ b/cmd/discover/main_test.go @@ -27,5 +27,5 @@ func TestMissingArguments(t *testing.T) { process, err := Start(cmd, nil, nil) gt.Expect(err).NotTo(HaveOccurred()) gt.Eventually(process, 5*time.Second).Should(Exit(1)) - gt.Expect(process.Err).To(gbytes.Say("empty string that is mandatory")) + gt.Expect(process.Err).To(gbytes.Say("IdentityPath|KeyPath is mandatory and cannot be empty")) }