Skip to content

Commit 73aa8da

Browse files
committed
FAB-16214 Remove pkg/errors dep from shim/ext
Replace with errors and fmt.Errorf FAB-16214 #done Change-Id: I68e1f3325ad1e5f63da96686212acbac19100205 Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent e39692d commit 73aa8da

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

core/chaincode/shim/ext/attrmgr/attrmgr.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
"crypto/x509/pkix"
2727
"encoding/asn1"
2828
"encoding/json"
29+
"errors"
2930
"fmt"
3031

3132
"github.com/golang/protobuf/proto"
3233
"github.com/hyperledger/fabric/protos/msp"
33-
"github.com/pkg/errors"
3434
)
3535

3636
var (
@@ -95,7 +95,7 @@ func (mgr *Mgr) ProcessAttributeRequests(requests []AttributeRequest, attributes
9595
attrsMap[name] = attr.GetValue()
9696
}
9797
if len(missingRequiredAttrs) > 0 {
98-
return nil, errors.Errorf("The following required attributes are missing: %+v",
98+
return nil, fmt.Errorf("the following required attributes are missing: %+v",
9999
missingRequiredAttrs)
100100
}
101101
return attrs, nil
@@ -105,7 +105,7 @@ func (mgr *Mgr) ProcessAttributeRequests(requests []AttributeRequest, attributes
105105
func (mgr *Mgr) AddAttributesToCert(attrs *Attributes, cert *x509.Certificate) error {
106106
buf, err := json.Marshal(attrs)
107107
if err != nil {
108-
return errors.Wrap(err, "Failed to marshal attributes")
108+
return fmt.Errorf("failed to marshal attributes: %s", err)
109109
}
110110
ext := pkix.Extension{
111111
Id: AttrOID,
@@ -128,7 +128,7 @@ func (mgr *Mgr) GetAttributesFromCert(cert *x509.Certificate) (*Attributes, erro
128128
if buf != nil {
129129
err := json.Unmarshal(buf, attrs)
130130
if err != nil {
131-
return nil, errors.Wrap(err, "Failed to unmarshal attributes from certificate")
131+
return nil, fmt.Errorf("failed to unmarshal attributes from certificate: %s", err)
132132
}
133133
}
134134
return attrs, nil
@@ -142,12 +142,12 @@ func (mgr *Mgr) GetAttributesFromIdemix(creator []byte) (*Attributes, error) {
142142
sid := &msp.SerializedIdentity{}
143143
err := proto.Unmarshal(creator, sid)
144144
if err != nil {
145-
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's identity")
145+
return nil, fmt.Errorf("failed to unmarshal transaction invoker's identity: %s", err)
146146
}
147147
idemixID := &msp.SerializedIdemixIdentity{}
148148
err = proto.Unmarshal(sid.IdBytes, idemixID)
149149
if err != nil {
150-
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's idemix identity")
150+
return nil, fmt.Errorf("failed to unmarshal transaction invoker's idemix identity: %s", err)
151151
}
152152
// Unmarshal into attributes object
153153
attrs := &Attributes{
@@ -157,14 +157,14 @@ func (mgr *Mgr) GetAttributesFromIdemix(creator []byte) (*Attributes, error) {
157157
ou := &msp.OrganizationUnit{}
158158
err = proto.Unmarshal(idemixID.Ou, ou)
159159
if err != nil {
160-
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's ou")
160+
return nil, fmt.Errorf("failed to unmarshal transaction invoker's ou: %s", err)
161161
}
162162
attrs.Attrs["ou"] = ou.OrganizationalUnitIdentifier
163163

164164
role := &msp.MSPRole{}
165165
err = proto.Unmarshal(idemixID.Role, role)
166166
if err != nil {
167-
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's role")
167+
return nil, fmt.Errorf("failed to unmarshal transaction invoker's role: %s", err)
168168
}
169169
var roleStr string
170170
switch role.Role {

core/chaincode/shim/ext/cid/cid.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/golang/protobuf/proto"
2929
"github.com/hyperledger/fabric/core/chaincode/shim/ext/attrmgr"
3030
"github.com/hyperledger/fabric/protos/msp"
31-
"github.com/pkg/errors"
3231
)
3332

3433
// GetID returns the ID associated with the invoking identity. This ID
@@ -127,10 +126,10 @@ func (c *clientIdentityImpl) AssertAttributeValue(attrName, attrValue string) er
127126
return err
128127
}
129128
if !ok {
130-
return errors.Errorf("Attribute '%s' was not found", attrName)
129+
return fmt.Errorf("attribute '%s' was not found", attrName)
131130
}
132131
if val != attrValue {
133-
return errors.Errorf("Attribute '%s' equals '%s', not '%s'", attrName, val, attrValue)
132+
return fmt.Errorf("attribute '%s' equals '%s', not '%s'", attrName, val, attrValue)
134133
}
135134
return nil
136135
}
@@ -153,18 +152,18 @@ func (c *clientIdentityImpl) init() error {
153152
if block == nil {
154153
err := c.getAttributesFromIdemix()
155154
if err != nil {
156-
return errors.WithMessage(err, "identity bytes are neither X509 PEM format nor an idemix credential")
155+
return fmt.Errorf("identity bytes are neither X509 PEM format nor an idemix credential: %s", err)
157156
}
158157
return nil
159158
}
160159
cert, err := x509.ParseCertificate(block.Bytes)
161160
if err != nil {
162-
return errors.WithMessage(err, "failed to parse certificate")
161+
return fmt.Errorf("failed to parse certificate: %s", err)
163162
}
164163
c.cert = cert
165164
attrs, err := attrmgr.New().GetAttributesFromCert(cert)
166165
if err != nil {
167-
return errors.WithMessage(err, "failed to get attributes from the transaction invoker's certificate")
166+
return fmt.Errorf("failed to get attributes from the transaction invoker's certificate: %s", err)
168167
}
169168
c.attrs = attrs
170169
return nil
@@ -176,11 +175,11 @@ func (c *clientIdentityImpl) getIdentity() (*msp.SerializedIdentity, error) {
176175
sid := &msp.SerializedIdentity{}
177176
creator, err := c.stub.GetCreator()
178177
if err != nil || creator == nil {
179-
return nil, errors.WithMessage(err, "failed to get transaction invoker's identity from the chaincode stub")
178+
return nil, fmt.Errorf("failed to get transaction invoker's identity from the chaincode stub: %s", err)
180179
}
181180
err = proto.Unmarshal(creator, sid)
182181
if err != nil {
183-
return nil, errors.Wrap(err, "failed to unmarshal transaction invoker's identity")
182+
return nil, fmt.Errorf("failed to unmarshal transaction invoker's identity: %s", err)
184183
}
185184
return sid, nil
186185
}
@@ -189,7 +188,7 @@ func (c *clientIdentityImpl) getAttributesFromIdemix() error {
189188
creator, err := c.stub.GetCreator()
190189
attrs, err := attrmgr.New().GetAttributesFromIdemix(creator)
191190
if err != nil {
192-
return errors.WithMessage(err, "failed to get attributes from the transaction invoker's idemix credential")
191+
return fmt.Errorf("failed to get attributes from the transaction invoker's idemix credential: %s", err)
193192
}
194193
c.attrs = attrs
195194
return nil

core/chaincode/shim/ext/entities/entities.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ package entities
88

99
import (
1010
"encoding/pem"
11+
"errors"
12+
"fmt"
1113
"reflect"
1214

1315
"github.com/hyperledger/fabric/bccsp"
14-
"github.com/pkg/errors"
1516
)
1617

1718
/**********************/
@@ -62,7 +63,7 @@ func NewAES256EncrypterEntity(ID string, b bccsp.BCCSP, key, IV []byte) (*BCCSPE
6263

6364
k, err := b.KeyImport(key, &bccsp.AES256ImportKeyOpts{Temporary: true})
6465
if err != nil {
65-
return nil, errors.WithMessage(err, "bccspInst.KeyImport failed")
66+
return nil, fmt.Errorf("bccspInst.KeyImport failed: %s", err)
6667
}
6768

6869
return NewEncrypterEntity(ID, b, k, &bccsp.AESCBCPKCS7ModeOpts{IV: IV}, &bccsp.AESCBCPKCS7ModeOpts{})
@@ -111,7 +112,7 @@ func NewECDSASignerEntity(ID string, b bccsp.BCCSP, signKeyBytes []byte) (*BCCSP
111112

112113
signKey, err := b.KeyImport(bl.Bytes, &bccsp.ECDSAPrivateKeyImportOpts{Temporary: true})
113114
if err != nil {
114-
return nil, errors.WithMessage(err, "bccspInst.KeyImport failed")
115+
return nil, fmt.Errorf("bccspInst.KeyImport failed: %s", err)
115116
}
116117

117118
return NewSignerEntity(ID, b, signKey, nil, &bccsp.SHA256Opts{})
@@ -130,7 +131,7 @@ func NewECDSAVerifierEntity(ID string, b bccsp.BCCSP, signKeyBytes []byte) (*BCC
130131

131132
signKey, err := b.KeyImport(bl.Bytes, &bccsp.ECDSAPKIXPublicKeyImportOpts{Temporary: true})
132133
if err != nil {
133-
return nil, errors.WithMessage(err, "bccspInst.KeyImport failed")
134+
return nil, fmt.Errorf("bccspInst.KeyImport failed: %s", err)
134135
}
135136

136137
return NewSignerEntity(ID, b, signKey, nil, &bccsp.SHA256Opts{})
@@ -171,7 +172,7 @@ func NewAES256EncrypterECDSASignerEntity(ID string, b bccsp.BCCSP, encKeyBytes,
171172

172173
encKey, err := b.KeyImport(encKeyBytes, &bccsp.AES256ImportKeyOpts{Temporary: true})
173174
if err != nil {
174-
return nil, errors.WithMessage(err, "bccspInst.KeyImport failed")
175+
return nil, fmt.Errorf("bccspInst.KeyImport failed: %s", err)
175176
}
176177

177178
bl, _ := pem.Decode(signKeyBytes)
@@ -181,7 +182,7 @@ func NewAES256EncrypterECDSASignerEntity(ID string, b bccsp.BCCSP, encKeyBytes,
181182

182183
signKey, err := b.KeyImport(bl.Bytes, &bccsp.ECDSAPrivateKeyImportOpts{Temporary: true})
183184
if err != nil {
184-
return nil, errors.WithMessage(err, "bccspInst.KeyImport failed")
185+
return nil, fmt.Errorf("bccspInst.KeyImport failed: %s", err)
185186
}
186187

187188
return NewEncrypterSignerEntity(ID, b, encKey, signKey, &bccsp.AESCBCPKCS7ModeOpts{}, &bccsp.AESCBCPKCS7ModeOpts{}, nil, &bccsp.SHA256Opts{})
@@ -260,7 +261,7 @@ func (pe *BCCSPEncrypterEntity) Public() (Entity, error) {
260261

261262
if !pe.EKey.Symmetric() {
262263
if eKeyPub, err = pe.EKey.PublicKey(); err != nil {
263-
return nil, errors.WithMessage(err, "public error, eKey.PublicKey returned")
264+
return nil, fmt.Errorf("public error, eKey.PublicKey failed: %s", err)
264265
}
265266
}
266267

@@ -289,7 +290,7 @@ func (e *BCCSPSignerEntity) Public() (Entity, error) {
289290

290291
if !e.SKey.Symmetric() {
291292
if sKeyPub, err = e.SKey.PublicKey(); err != nil {
292-
return nil, errors.WithMessage(err, "public error, sKey.PublicKey returned")
293+
return nil, fmt.Errorf("public error, sKey.PublicKey failed: %s", err)
293294
}
294295
}
295296

@@ -307,7 +308,7 @@ func (e *BCCSPSignerEntity) Public() (Entity, error) {
307308
func (e *BCCSPSignerEntity) Sign(msg []byte) ([]byte, error) {
308309
h, err := e.BCCSP.Hash(msg, e.HOpts)
309310
if err != nil {
310-
return nil, errors.WithMessage(err, "sign error: bccsp.Hash returned")
311+
return nil, fmt.Errorf("sign error: bccsp.Hash failed: %s", err)
311312
}
312313

313314
return e.BCCSP.Sign(e.SKey, h, e.SOpts)
@@ -316,7 +317,7 @@ func (e *BCCSPSignerEntity) Sign(msg []byte) ([]byte, error) {
316317
func (e *BCCSPSignerEntity) Verify(signature, msg []byte) (bool, error) {
317318
h, err := e.BCCSP.Hash(msg, e.HOpts)
318319
if err != nil {
319-
return false, errors.WithMessage(err, "sign error: bccsp.Hash returned")
320+
return false, fmt.Errorf("sign error: bccsp.Hash failed: %s", err)
320321
}
321322

322323
return e.BCCSP.Verify(e.SKey, signature, h, e.SOpts)
@@ -328,13 +329,13 @@ func (pe *BCCSPEncrypterSignerEntity) Public() (Entity, error) {
328329

329330
if !pe.EKey.Symmetric() {
330331
if eKeyPub, err = pe.EKey.PublicKey(); err != nil {
331-
return nil, errors.WithMessage(err, "public error, eKey.PublicKey returned")
332+
return nil, fmt.Errorf("public error, eKey.PublicKey failed: %s", err)
332333
}
333334
}
334335

335336
sKeyPub, err := pe.SKey.PublicKey()
336337
if err != nil {
337-
return nil, errors.WithMessage(err, "public error, sKey.PublicKey returned")
338+
return nil, fmt.Errorf("public error, sKey.PublicKey failed: %s", err)
338339
}
339340

340341
return &BCCSPEncrypterSignerEntity{

core/chaincode/shim/ext/entities/message.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package entities
88

99
import (
1010
"encoding/json"
11-
12-
"github.com/pkg/errors"
11+
"errors"
12+
"fmt"
1313
)
1414

1515
// SignedMessage is a simple struct that contains space
@@ -35,11 +35,11 @@ func (m *SignedMessage) Sign(signer Signer) error {
3535
m.Sig = nil
3636
bytes, err := json.Marshal(m)
3737
if err != nil {
38-
return errors.Wrap(err, "sign error: json.Marshal returned")
38+
return fmt.Errorf("sign error: json.Marshal failed: %s", err)
3939
}
4040
sig, err := signer.Sign(bytes)
4141
if err != nil {
42-
return errors.WithMessage(err, "sign error: signer.Sign returned")
42+
return fmt.Errorf("sign error: signer.Sign failed: %s", err)
4343
}
4444
m.Sig = sig
4545

@@ -60,7 +60,7 @@ func (m *SignedMessage) Verify(verifier Signer) (bool, error) {
6060

6161
bytes, err := json.Marshal(m)
6262
if err != nil {
63-
return false, errors.Wrap(err, "sign error: json.Marshal returned")
63+
return false, fmt.Errorf("sign error: json.Marshal failed: %s", err)
6464
}
6565

6666
return verifier.Verify(sig, bytes)

core/chaincode/shim/ext/statebased/statebasedimpl.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/golang/protobuf/proto"
1414
"github.com/hyperledger/fabric/protos/common"
1515
"github.com/hyperledger/fabric/protos/msp"
16-
"github.com/pkg/errors"
1716
)
1817

1918
// stateEP implements the KeyEndorsementPolicy
@@ -96,7 +95,7 @@ func (s *stateEP) setMSPIDsFromSP(sp *common.SignaturePolicyEnvelope) error {
9695
msprole := &msp.MSPRole{}
9796
err := proto.Unmarshal(identity.Principal, msprole)
9897
if err != nil {
99-
return errors.Wrapf(err, "error unmarshaling msp principal")
98+
return fmt.Errorf("error unmarshaling msp principal: %s", err)
10099
}
101100
s.orgs[msprole.GetMspIdentifier()] = msprole.GetRole()
102101
}

0 commit comments

Comments
 (0)