Skip to content

Commit

Permalink
chore(errors): Cleanup (#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear authored Aug 15, 2024
1 parent 0f4aa51 commit 64872ae
Show file tree
Hide file tree
Showing 29 changed files with 190 additions and 173 deletions.
8 changes: 8 additions & 0 deletions examples/berad/pkg/state-transition/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ var (
// ErrStateRootMismatch is returned when the state root in a block header
// does not match the expected value.
ErrStateRootMismatch = errors.New("state root mismatch")

// ErrExceedMaximumWithdrawals is returned when the number of withdrawals
// in a block exceeds the maximum allowed.
ErrExceedMaximumWithdrawals = errors.New("exceeds maximum withdrawals")

// ErrNumWithdrawalsMismatch is returned when the number of withdrawals
// in a block does not match the expected value.
ErrNumWithdrawalsMismatch = errors.New("number of withdrawals mismatch")
)
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (sp *StateProcessor[
if withdrawals := payload.GetWithdrawals(); uint64(
len(payload.GetWithdrawals()),
) > sp.cs.MaxWithdrawalsPerPayload() {
return errors.Newf(
return errors.Wrapf(
ErrExceedMaximumWithdrawals,
"too many withdrawals, expected: %d, got: %d",
sp.cs.MaxWithdrawalsPerPayload(), len(withdrawals),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ func (sp *StateProcessor[

// Ensure the withdrawals have the same length
if numWithdrawals != len(payloadWithdrawals) {
return errors.Newf(
return errors.Wrapf(
ErrNumWithdrawalsMismatch,
"withdrawals do not match expected length %d, got %d",
len(expectedWithdrawals), len(payloadWithdrawals),
)
Expand All @@ -215,7 +216,8 @@ func (sp *StateProcessor[
for i, wd := range expectedWithdrawals {
// Ensure the withdrawals match the local state.
if !wd.Equals(payloadWithdrawals[i]) {
return errors.Newf(
return errors.Wrapf(
ErrNumWithdrawalsMismatch,
"withdrawals do not match expected %s, got %s",
spew.Sdump(wd), spew.Sdump(payloadWithdrawals[i]),
)
Expand Down
11 changes: 2 additions & 9 deletions mod/beacon/validator/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/errors"
"github.com/berachain/beacon-kit/mod/primitives/pkg/bytes"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/crypto"
Expand Down Expand Up @@ -145,21 +144,15 @@ func (s *Service[
)

if err != nil {
return blk, errors.Newf(
"failed to get block root at index: %w",
err,
)
return blk, err
}

// Get the proposer index for the slot.
proposerIndex, err := st.ValidatorIndexByPubkey(
s.signer.PublicKey(),
)
if err != nil {
return blk, errors.Newf(
"failed to get validator by pubkey: %w",
err,
)
return blk, err
}

return blk.NewWithVersion(
Expand Down
4 changes: 2 additions & 2 deletions mod/cli/pkg/commands/genesis/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
func makeOutputFilepath(rootDir, pubkey string) (string, error) {
writePath := filepath.Join(rootDir, "config", "premined-deposits")
if err := afero.NewOsFs().MkdirAll(writePath, os.ModePerm); err != nil {
return "", errors.Newf(
"could not create directory %q: %w",
return "", errors.Wrapf(
errors.New("could not create directory"), "%q: %w",
writePath,
err,
)
Expand Down
15 changes: 4 additions & 11 deletions mod/cli/pkg/commands/genesis/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,11 @@ func AddExecutionPayloadCmd(chainSpec common.ChainSpec) *cobra.Command {
}

// Inject the execution payload.
header, err := executableDataToExecutionPayloadHeader(
genesisInfo.ExecutionPayloadHeader = executableDataToExecutionPayloadHeader(
version.ToUint32(genesisInfo.ForkVersion),
payload,
chainSpec.MaxWithdrawalsPerPayload(),
)
if err != nil {
return errors.Wrap(
err,
"failed to convert executable data to execution payload header",
)
}
genesisInfo.ExecutionPayloadHeader = header

appGenesisState["beacon"], err = json.Marshal(genesisInfo)
if err != nil {
Expand All @@ -131,7 +124,7 @@ func executableDataToExecutionPayloadHeader(
data *gethprimitives.ExecutableData,
// todo: re-enable when codec supports.
_ uint64,
) (*types.ExecutionPayloadHeader, error) {
) *types.ExecutionPayloadHeader {
var executionPayloadHeader *types.ExecutionPayloadHeader
switch forkVersion {
case version.Deneb, version.DenebPlus:
Expand Down Expand Up @@ -187,8 +180,8 @@ func executableDataToExecutionPayloadHeader(
ExcessBlobGas: math.U64(excessBlobGas),
}
default:
return nil, errors.Newf("unsupported fork version %d", forkVersion)
panic("unsupported fork version")
}

return executionPayloadHeader, nil
return executionPayloadHeader
}
27 changes: 27 additions & 0 deletions mod/cli/pkg/config/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package config

import "errors"

// ErrFlagBind is returned when there is an error binding a flag to the viper
// instance.
var ErrFlagBind = errors.New("failed to bind flag")
2 changes: 1 addition & 1 deletion mod/cli/pkg/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func InitializeCmd[

// bind cobra flags to the viper instance
if err = bindFlags(baseName, cmd, viper); err != nil {
return errors.Newf("error binding flags: %w", err)
return errors.Wrapf(ErrFlagBind, "error binding flags: %w", err)
}

ctx := cmd.Context()
Expand Down
7 changes: 2 additions & 5 deletions mod/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func MustReadConfigFromAppOpts(opts AppOptions) *Config {
func ReadConfigFromAppOpts(opts AppOptions) (*Config, error) {
v, ok := opts.(*viper.Viper)
if !ok {
return nil, errors.Newf("invalid application options type: %T", opts)
return nil, errors.New("invalid application options type")
}

type cfgUnmarshaller struct {
Expand All @@ -116,10 +116,7 @@ func ReadConfigFromAppOpts(opts AppOptions) (*Config, error) {
viperlib.StringToDialURLFunc(),
viperlib.StringToConnectionURLFunc(),
))); err != nil {
return nil, errors.Newf(
"failed to decode beacon-kit configuration: %w",
err,
)
return nil, err
}

return &cfg.BeaconKit, nil
Expand Down
19 changes: 1 addition & 18 deletions mod/errors/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,4 @@ module github.com/berachain/beacon-kit/mod/errors

go 1.23.0

require github.com/cockroachdb/errors v1.11.3

require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
)
require github.com/pkg/errors v0.9.1
66 changes: 0 additions & 66 deletions mod/errors/go.sum
Original file line number Diff line number Diff line change
@@ -1,68 +1,2 @@
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k=
github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20 changes: 15 additions & 5 deletions mod/errors/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
package errors

import (
"github.com/cockroachdb/errors"
stderrors "errors"

"github.com/pkg/errors"
)

// TODO: eventually swap out via build flags if we believe there is value
Expand All @@ -30,15 +32,23 @@ import (
//nolint:gochecknoglobals // used an alias.
var (
New = errors.New
Newf = errors.Newf
Wrap = errors.Wrap
Wrapf = errors.Wrapf
Is = errors.Is
IsAny = errors.IsAny
As = errors.As
Join = errors.Join
Join = stderrors.Join
)

// IsAny checks if the provided error is any of the provided errors.
func IsAny(err error, errs ...error) bool {
for _, e := range errs {
if errors.Is(err, e) {
return true
}
}
return false
}

// DetailedError is a custom error type that includes a message and a flag
// indicating if the error is fatal.
type DetailedError struct {
Expand Down Expand Up @@ -104,7 +114,7 @@ func JoinFatal(errs ...error) error {
break
}
}
retErr := errors.Join(errs...)
retErr := stderrors.Join(errs...)
if fatal {
return WrapFatal(retErr)
}
Expand Down
4 changes: 2 additions & 2 deletions mod/node-api/handlers/proof/merkle/block_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func verifyProposerInBlock(
); err != nil {
return common.Root{}, err
} else if !beaconRootVerified {
return common.Root{}, errors.Newf(
"proof failed to verify against beacon root: 0x%x", beaconRoot[:],
return common.Root{}, errors.New(
"proof failed to verify against beacon root",
)
}

Expand Down
5 changes: 3 additions & 2 deletions mod/node-api/handlers/proof/merkle/execution_fee_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ func verifyExecutionFeeRecipientInBlock(
); err != nil {
return common.Root{}, err
} else if !beaconRootVerified {
return common.Root{}, errors.Newf(
"proof failed to verify against beacon root: 0x%x", beaconRoot[:],
return common.Root{}, errors.Wrapf(
errors.New("proof failed to verify against beacon root"),
"beacon root: 0x%x", beaconRoot[:],
)
}

Expand Down
5 changes: 3 additions & 2 deletions mod/node-api/handlers/proof/merkle/execution_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ func verifyExecutionNumberInBlock(
); err != nil {
return common.Root{}, err
} else if !beaconRootVerified {
return common.Root{}, errors.Newf(
"proof failed to verify against beacon root: 0x%x", beaconRoot[:],
return common.Root{}, errors.Wrapf(
errors.New("proof failed to verify against beacon root"),
"beacon root: 0x%x", beaconRoot[:],
)
}

Expand Down
10 changes: 2 additions & 8 deletions mod/primitives/pkg/bytes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ func UnmarshalJSONHelper(target []byte, input []byte) error {
return err
}
if len(bz) != len(target) {
return errors.Newf(
"incorrect length, expected %d bytes but got %d",
len(target), len(bz),
)
return errors.New("incorrect length")
}
copy(target, bz)
return nil
Expand All @@ -50,10 +47,7 @@ func UnmarshalTextHelper(target []byte, text []byte) error {
return err
}
if len(bz) != len(target) {
return errors.Newf(
"incorrect length, expected %d bytes but got %d",
len(target), len(bz),
)
return errors.New("incorrect length")
}
copy(target, bz)
return nil
Expand Down
3 changes: 2 additions & 1 deletion mod/primitives/pkg/encoding/hex/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func DecodeFixedText(input, out []byte) error {
return err
}
if len(raw)/encDecRatio != len(out) {
return errors.Newf(
return errors.Wrapf(
errors.New("invalid hex string length"),
"hex string has length %d, want %d",
len(raw), len(out)*encDecRatio,
)
Expand Down
Loading

0 comments on commit 64872ae

Please sign in to comment.