From a28fcc094b918b1e90374a7443b14741070b5cfe Mon Sep 17 00:00:00 2001 From: ChengenH Date: Fri, 13 Dec 2024 16:34:18 +0800 Subject: [PATCH] refactor: unify the error handling methods in the crypto package that are different from the project style Signed-off-by: ChengenH --- cmd/clef/main.go | 4 ++-- console/console.go | 2 +- core/blockchain.go | 4 ++-- rpc/subscription.go | 4 ++-- trie/iterator.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index dde4ae853f..99bfeac4d2 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -923,13 +923,13 @@ func testExternalUI(api *core.SignerAPI) { } } expectApprove := func(testcase string, err error) { - if err == nil || err == accounts.ErrUnknownAccount { + if err == nil || errors.Is(err, accounts.ErrUnknownAccount) { return } addErr(fmt.Sprintf("%v: expected no error, got %v", testcase, err.Error())) } expectDeny := func(testcase string, err error) { - if err == nil || err != core.ErrRequestDenied { + if err == nil || !errors.Is(err, core.ErrRequestDenied) { addErr(fmt.Sprintf("%v: expected ErrRequestDenied, got %v", testcase, err)) } } diff --git a/console/console.go b/console/console.go index b5c77bd78f..7774cbfba7 100644 --- a/console/console.go +++ b/console/console.go @@ -423,7 +423,7 @@ func (c *Console) Interactive() { return case err := <-inputErr: - if err == liner.ErrPromptAborted { + if errors.Is(err, liner.ErrPromptAborted) { // When prompting for multi-line input, the first Ctrl-C resets // the multi-line state. prompt, indents, input = c.prompt, 0, "" diff --git a/core/blockchain.go b/core/blockchain.go index 0fe4812626..fdd3f04689 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1385,7 +1385,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ // Write downloaded chain data and corresponding receipt chain data if len(ancientBlocks) > 0 { if n, err := writeAncient(ancientBlocks, ancientReceipts); err != nil { - if err == errInsertionInterrupted { + if errors.Is(err, errInsertionInterrupted) { return 0, nil } return n, err @@ -1393,7 +1393,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ } if len(liveBlocks) > 0 { if n, err := writeLive(liveBlocks, liveReceipts); err != nil { - if err == errInsertionInterrupted { + if errors.Is(err, errInsertionInterrupted) { return 0, nil } return n, err diff --git a/rpc/subscription.go b/rpc/subscription.go index 9e400c8b60..5fa7244167 100644 --- a/rpc/subscription.go +++ b/rpc/subscription.go @@ -304,7 +304,7 @@ func (sub *ClientSubscription) run() { // Send the error. if err != nil { - if err == ErrClientQuit { + if errors.Is(err, ErrClientQuit) { // ErrClientQuit gets here when Client.Close is called. This is reported as a // nil error because it's not an error, but we can't close sub.err here. err = nil @@ -340,7 +340,7 @@ func (sub *ClientSubscription) forward() (unsubscribeServer bool, err error) { if !recv.IsNil() { err = recv.Interface().(error) } - if err == errUnsubscribed { + if errors.Is(err, errUnsubscribed) { // Exiting because Unsubscribe was called, unsubscribe on server. return true, nil } diff --git a/trie/iterator.go b/trie/iterator.go index fa01611063..a53fc97c26 100644 --- a/trie/iterator.go +++ b/trie/iterator.go @@ -308,7 +308,7 @@ func (it *nodeIterator) seek(prefix []byte) error { // Move forward until we're just before the closest match to key. for { state, parentIndex, path, err := it.peekSeek(key) - if err == errIteratorEnd { + if errors.Is(err, errIteratorEnd) { return errIteratorEnd } else if err != nil { return seekError{prefix, err}