Skip to content

Commit

Permalink
[blockchain-v4] blockchain: Address some linter complaints.
Browse files Browse the repository at this point in the history
  • Loading branch information
davecgh committed Oct 10, 2022
1 parent 0b3e9a9 commit 93fb5da
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions blockchain/chainio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestBlockIndexDecodeErrors(t *testing.T) {
// Ensure the expected error type is returned.
gotBytesRead, err := decodeBlockIndexEntry(test.serialized,
&test.entry)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestStxoDecodeErrors(t *testing.T) {
gotBytesRead, err := decodeSpentTxOut(test.serialized,
&test.stxo, test.stxo.amount, test.stxo.blockHeight, test.stxo.blockIndex,
test.txOutIndex)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down Expand Up @@ -777,7 +777,7 @@ func TestSpendJournalErrors(t *testing.T) {
// slice is nil.
stxos, err := deserializeSpendJournalEntry(test.serialized,
test.blockTxns, noTreasury)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down
9 changes: 9 additions & 0 deletions blockchain/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ func (e AssertError) Error() string {
return "assertion failed: " + string(e)
}

// Is implements the interface to work with the standard library's errors.Is.
//
// It returns true in the following cases:
// - The target is AssertError
func (e AssertError) Is(target error) bool {
var err AssertError
return errors.As(target, &err)
}

// ErrorKind identifies a kind of error. It has full support for errors.Is and
// errors.As, so the caller can directly check against an error kind when
// determining the reason for an error.
Expand Down
2 changes: 1 addition & 1 deletion blockchain/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestBlockIndexDecodeErrorsV2(t *testing.T) {
// Ensure the expected error type is returned.
gotBytesRead, err := decodeBlockIndexEntryV2(test.serialized,
&test.entry)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("decodeBlockIndexEntry (%s): expected error "+
"type does not match - got %T, want %T",
test.name, err, test.errType)
Expand Down
6 changes: 3 additions & 3 deletions blockchain/utxoio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestUtxoEntryDeserializeErrors(t *testing.T) {
// Ensure the expected error type is returned and the returned
// entry is nil.
entry, err := deserializeUtxoEntry(test.serialized, test.txOutIndex)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestUtxoSetStateDeserializeErrors(t *testing.T) {
// Ensure the expected error type is returned and the returned
// utxo set state is nil.
entry, err := deserializeUtxoSetState(test.serialized)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestDecodeOutpointKeyErrors(t *testing.T) {
// Ensure the expected error type is returned.
var gotOutpoint wire.OutPoint
err := decodeOutpointKey(test.serialized, &gotOutpoint)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down

0 comments on commit 93fb5da

Please sign in to comment.