refactor: unify the error handling methods in the crypto package that are different from the project style

Signed-off-by: ChengenH <hce19970702@gmail.com>
This commit is contained in:
ChengenH 2024-12-13 16:34:18 +08:00
parent 88cbfab332
commit a28fcc094b
5 changed files with 8 additions and 8 deletions

View file

@ -923,13 +923,13 @@ func testExternalUI(api *core.SignerAPI) {
} }
} }
expectApprove := func(testcase string, err error) { expectApprove := func(testcase string, err error) {
if err == nil || err == accounts.ErrUnknownAccount { if err == nil || errors.Is(err, accounts.ErrUnknownAccount) {
return return
} }
addErr(fmt.Sprintf("%v: expected no error, got %v", testcase, err.Error())) addErr(fmt.Sprintf("%v: expected no error, got %v", testcase, err.Error()))
} }
expectDeny := func(testcase string, 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)) addErr(fmt.Sprintf("%v: expected ErrRequestDenied, got %v", testcase, err))
} }
} }

View file

@ -423,7 +423,7 @@ func (c *Console) Interactive() {
return return
case err := <-inputErr: case err := <-inputErr:
if err == liner.ErrPromptAborted { if errors.Is(err, liner.ErrPromptAborted) {
// When prompting for multi-line input, the first Ctrl-C resets // When prompting for multi-line input, the first Ctrl-C resets
// the multi-line state. // the multi-line state.
prompt, indents, input = c.prompt, 0, "" prompt, indents, input = c.prompt, 0, ""

View file

@ -1385,7 +1385,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
// Write downloaded chain data and corresponding receipt chain data // Write downloaded chain data and corresponding receipt chain data
if len(ancientBlocks) > 0 { if len(ancientBlocks) > 0 {
if n, err := writeAncient(ancientBlocks, ancientReceipts); err != nil { if n, err := writeAncient(ancientBlocks, ancientReceipts); err != nil {
if err == errInsertionInterrupted { if errors.Is(err, errInsertionInterrupted) {
return 0, nil return 0, nil
} }
return n, err return n, err
@ -1393,7 +1393,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
} }
if len(liveBlocks) > 0 { if len(liveBlocks) > 0 {
if n, err := writeLive(liveBlocks, liveReceipts); err != nil { if n, err := writeLive(liveBlocks, liveReceipts); err != nil {
if err == errInsertionInterrupted { if errors.Is(err, errInsertionInterrupted) {
return 0, nil return 0, nil
} }
return n, err return n, err

View file

@ -304,7 +304,7 @@ func (sub *ClientSubscription) run() {
// Send the error. // Send the error.
if err != nil { if err != nil {
if err == ErrClientQuit { if errors.Is(err, ErrClientQuit) {
// ErrClientQuit gets here when Client.Close is called. This is reported as a // 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. // nil error because it's not an error, but we can't close sub.err here.
err = nil err = nil
@ -340,7 +340,7 @@ func (sub *ClientSubscription) forward() (unsubscribeServer bool, err error) {
if !recv.IsNil() { if !recv.IsNil() {
err = recv.Interface().(error) err = recv.Interface().(error)
} }
if err == errUnsubscribed { if errors.Is(err, errUnsubscribed) {
// Exiting because Unsubscribe was called, unsubscribe on server. // Exiting because Unsubscribe was called, unsubscribe on server.
return true, nil return true, nil
} }

View file

@ -308,7 +308,7 @@ func (it *nodeIterator) seek(prefix []byte) error {
// Move forward until we're just before the closest match to key. // Move forward until we're just before the closest match to key.
for { for {
state, parentIndex, path, err := it.peekSeek(key) state, parentIndex, path, err := it.peekSeek(key)
if err == errIteratorEnd { if errors.Is(err, errIteratorEnd) {
return errIteratorEnd return errIteratorEnd
} else if err != nil { } else if err != nil {
return seekError{prefix, err} return seekError{prefix, err}