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) {
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))
}
}

View file

@ -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, ""

View file

@ -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

View file

@ -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
}

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.
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}