From ab50856a4ed3dec7b2597c1a5fa7d71cd5aecb20 Mon Sep 17 00:00:00 2001 From: Jay Guo Date: Wed, 6 Nov 2019 17:33:10 +0800 Subject: [PATCH] FAB-16940 report underlying error msg in configtx Change-Id: I1479d12829216c22be68694a167d1bd59a1afce5 Signed-off-by: Jay Guo --- common/configtx/configmap.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/configtx/configmap.go b/common/configtx/configmap.go index 3b7f9f94c70..9ea4f4fec2a 100644 --- a/common/configtx/configmap.go +++ b/common/configtx/configmap.go @@ -7,12 +7,12 @@ SPDX-License-Identifier: Apache-2.0 package configtx import ( - "fmt" "strings" "github.com/golang/protobuf/proto" cb "github.com/hyperledger/fabric-protos-go/common" "github.com/hyperledger/fabric/protoutil" + "github.com/pkg/errors" ) const ( @@ -54,7 +54,7 @@ func addToMap(cg comparable, result map[string]comparable) error { } if err := validateConfigID(cg.key); err != nil { - return fmt.Errorf("Illegal characters in key: %s", fqPath) + return errors.WithMessagef(err, "illegal characters in key: %s", fqPath) } if len(cg.path) == 0 { @@ -113,11 +113,11 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG groupPath := groupPrefix + path group, ok := configMap[groupPath] if !ok { - return nil, fmt.Errorf("Missing group at path: %s", groupPath) + return nil, errors.Errorf("missing group at path: %s", groupPath) } if group.ConfigGroup == nil { - return nil, fmt.Errorf("ConfigGroup not found at group path: %s", groupPath) + return nil, errors.Errorf("ConfigGroup not found at group path: %s", groupPath) } newConfigGroup := protoutil.NewConfigGroup() @@ -135,10 +135,10 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG valuePath := valuePrefix + path + pathSeparator + key value, ok := configMap[valuePath] if !ok { - return nil, fmt.Errorf("Missing value at path: %s", valuePath) + return nil, errors.Errorf("missing value at path: %s", valuePath) } if value.ConfigValue == nil { - return nil, fmt.Errorf("ConfigValue not found at value path: %s", valuePath) + return nil, errors.Errorf("ConfigValue not found at value path: %s", valuePath) } newConfigGroup.Values[key] = proto.Clone(value.ConfigValue).(*cb.ConfigValue) } @@ -147,10 +147,10 @@ func recurseConfigMap(path string, configMap map[string]comparable) (*cb.ConfigG policyPath := policyPrefix + path + pathSeparator + key policy, ok := configMap[policyPath] if !ok { - return nil, fmt.Errorf("Missing policy at path: %s", policyPath) + return nil, errors.Errorf("missing policy at path: %s", policyPath) } if policy.ConfigPolicy == nil { - return nil, fmt.Errorf("ConfigPolicy not found at policy path: %s", policyPath) + return nil, errors.Errorf("ConfigPolicy not found at policy path: %s", policyPath) } newConfigGroup.Policies[key] = proto.Clone(policy.ConfigPolicy).(*cb.ConfigPolicy) logger.Debugf("Setting policy for key %s to %+v", key, group.Policies[key])