Wrap errors (#3123)

This commit is contained in:
Preston Van Loon
2019-08-01 22:27:38 -04:00
committed by terence tsao
parent 7eca7ba43b
commit 953c59a302
73 changed files with 351 additions and 307 deletions

View File

@@ -8,6 +8,7 @@ go_library(
deps = [
"//shared/bytesutil:go_default_library",
"@com_github_phoreproject_bls//g1pubs:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)

View File

@@ -8,6 +8,7 @@ import (
"io"
g1 "github.com/phoreproject/bls/g1pubs"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
@@ -30,7 +31,7 @@ type PublicKey struct {
func RandKey(r io.Reader) (*SecretKey, error) {
k, err := g1.RandKey(r)
if err != nil {
return nil, fmt.Errorf("could not initialize secret key: %v", err)
return nil, errors.Wrap(err, "could not initialize secret key")
}
return &SecretKey{val: k}, nil
}
@@ -49,7 +50,7 @@ func PublicKeyFromBytes(pub []byte) (*PublicKey, error) {
b := bytesutil.ToBytes48(pub)
k, err := g1.DeserializePublicKey(b)
if err != nil {
return nil, fmt.Errorf("could not unmarshal bytes into public key: %v", err)
return nil, errors.Wrap(err, "could not unmarshal bytes into public key")
}
return &PublicKey{val: k}, nil
}
@@ -59,7 +60,7 @@ func SignatureFromBytes(sig []byte) (*Signature, error) {
b := bytesutil.ToBytes96(sig)
s, err := g1.DeserializeSignature(b)
if err != nil {
return nil, fmt.Errorf("could not unmarshal bytes into signature: %v", err)
return nil, errors.Wrap(err, "could not unmarshal bytes into signature")
}
return &Signature{val: s}, nil
}

View File

@@ -16,6 +16,7 @@ go_library(
"//shared/bls:go_default_library",
"//shared/params:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@org_golang_x_crypto//pbkdf2:go_default_library",
"@org_golang_x_crypto//scrypt:go_default_library",

View File

@@ -21,13 +21,13 @@ package keystore
import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/bls"
)
@@ -154,7 +154,7 @@ func newKeyFromBLS(blsKey *bls.SecretKey) (*Key, error) {
func NewKey(rand io.Reader) (*Key, error) {
secretKey, err := bls.RandKey(rand)
if err != nil {
return nil, fmt.Errorf("could not generate random key: %v", err)
return nil, errors.Wrap(err, "could not generate random key")
}
return newKeyFromBLS(secretKey)
}

View File

@@ -5,7 +5,10 @@ go_library(
srcs = ["pagination.go"],
importpath = "github.com/prysmaticlabs/prysm/shared/pagination",
visibility = ["//visibility:public"],
deps = ["//shared/params:go_default_library"],
deps = [
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
)
go_test(

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/params"
)
@@ -19,7 +20,7 @@ func StartAndEndPage(pageToken string, pageSize int, totalSize int) (int, int, s
token, err := strconv.Atoi(pageToken)
if err != nil {
return 0, 0, "", fmt.Errorf("could not convert page token: %v", err)
return 0, 0, "", errors.Wrap(err, "could not convert page token")
}
// Start page can not be greater than validator size.

View File

@@ -23,6 +23,7 @@ go_library(
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_json_iterator_go//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],

View File

@@ -3,10 +3,10 @@ package testutil
import (
"crypto/rand"
"encoding/binary"
"fmt"
"sync"
"testing"
"github.com/pkg/errors"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@@ -134,7 +134,7 @@ func CreateRandaoReveal(beaconState *pb.BeaconState, epoch uint64, privKeys []*b
// We fetch the proposer's index as that is whom the RANDAO will be verified against.
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
if err != nil {
return []byte{}, fmt.Errorf("could not get beacon proposer index: %v", err)
return []byte{}, errors.Wrap(err, "could not get beacon proposer index")
}
buf := make([]byte, 32)
binary.LittleEndian.PutUint64(buf, epoch)