From a506e3e4601d1aff415d008a1f5c9f4c3e7f0fed Mon Sep 17 00:00:00 2001 From: Andi <36215014+ChengenH@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:40:06 +0800 Subject: [PATCH] refactor: unify the error handling methods in the crypto package that are different from the project style (#13097) Signed-off-by: ChengenH --- cl/beacon/builder/client.go | 4 ++-- cl/beacon/handler/block_production.go | 2 +- cl/phase1/forkchoice/on_block.go | 2 +- cl/phase1/network/services/block_service.go | 2 +- rpc/subscription.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cl/beacon/builder/client.go b/cl/beacon/builder/client.go index 39b4b69b63b..ab0328a5d0e 100644 --- a/cl/beacon/builder/client.go +++ b/cl/beacon/builder/client.go @@ -76,7 +76,7 @@ func (b *builderClient) RegisterValidator(ctx context.Context, registers []*clty return err } _, err = httpCall[json.RawMessage](ctx, b.httpClient, http.MethodPost, url, nil, bytes.NewBuffer(payload)) - if err == ErrNoContent { + if errors.Is(err, ErrNoContent) { // no content is ok return nil } @@ -144,7 +144,7 @@ func (b *builderClient) GetStatus(ctx context.Context) error { path := "/eth/v1/builder/status" url := b.url.JoinPath(path).String() _, err := httpCall[json.RawMessage](ctx, b.httpClient, http.MethodGet, url, nil, nil) - if err == ErrNoContent { + if errors.Is(err, ErrNoContent) { // no content is ok, we just need to check if the server is up return nil } diff --git a/cl/beacon/handler/block_production.go b/cl/beacon/handler/block_production.go index 18c5c1e656d..bfc24b096e7 100644 --- a/cl/beacon/handler/block_production.go +++ b/cl/beacon/handler/block_production.go @@ -212,7 +212,7 @@ func (a *ApiHandler) GetEthV1ValidatorAttestationData( *committeeIndex, ) - if err == attestation_producer.ErrHeadStateBehind { + if errors.Is(err, attestation_producer.ErrHeadStateBehind) { return beaconhttp.NewEndpointError( http.StatusServiceUnavailable, synced_data.ErrNotSynced, diff --git a/cl/phase1/forkchoice/on_block.go b/cl/phase1/forkchoice/on_block.go index 56acb2d307f..8764d679504 100644 --- a/cl/phase1/forkchoice/on_block.go +++ b/cl/phase1/forkchoice/on_block.go @@ -188,7 +188,7 @@ func (f *ForkChoiceStore) OnBlock(ctx context.Context, block *cltypes.SignedBeac // Check if blob data is available if block.Version() >= clparams.DenebVersion && checkDataAvaiability { if err := f.isDataAvailable(ctx, block.Block.Slot, blockRoot, block.Block.Body.BlobKzgCommitments); err != nil { - if err == ErrEIP4844DataNotAvailable { + if errors.Is(err, ErrEIP4844DataNotAvailable) { return err } return fmt.Errorf("OnBlock: data is not available for block %x: %v", libcommon.Hash(blockRoot), err) diff --git a/cl/phase1/network/services/block_service.go b/cl/phase1/network/services/block_service.go index a7fab891c70..acda79ebd43 100644 --- a/cl/phase1/network/services/block_service.go +++ b/cl/phase1/network/services/block_service.go @@ -159,7 +159,7 @@ func (b *blockService) ProcessMessage(ctx context.Context, _ *uint64, msg *cltyp b.publishBlockGossipEvent(msg) // the rest of the validation is done in the forkchoice store if err := b.processAndStoreBlock(ctx, msg); err != nil { - if err == forkchoice.ErrEIP4844DataNotAvailable { + if errors.Is(err, forkchoice.ErrEIP4844DataNotAvailable) { b.scheduleBlockForLaterProcessing(msg) return ErrIgnore } diff --git a/rpc/subscription.go b/rpc/subscription.go index 6bf15f50582..ed76f2a34fc 100644 --- a/rpc/subscription.go +++ b/rpc/subscription.go @@ -260,7 +260,7 @@ func (sub *ClientSubscription) quitWithError(unsubscribeServer bool, err error) sub.requestUnsubscribe() } if err != nil { - if err == ErrClientQuit { + if errors.Is(err, ErrClientQuit) { err = nil // Adhere to subscription semantics. } sub.err <- err