Repository: decred/dcrd
Pull request #2965 (2022-06-23 23:05:48)

blockchain: Address some linter complaints.


Patch:
diff --git a/internal/blockchain/error.go b/internal/blockchain/error.go
index a0e5c69b..636eb873 100644
--- a/internal/blockchain/error.go
+++ b/internal/blockchain/error.go
@@ -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.


Test patch:
diff --git a/internal/blockchain/chainio_test.go b/internal/blockchain/chainio_test.go
index 8793f3f2..1970cdc4 100644
--- a/internal/blockchain/chainio_test.go
+++ b/internal/blockchain/chainio_test.go
@@ -311,7 +311,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
@@ -527,7 +527,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
@@ -779,7 +779,7 @@ func TestSpendJournalErrors(t *testing.T) {
 		// slice is nil.
 		stxos, err := deserializeSpendJournalEntry(test.serialized,
 			test.blockTxns)
-		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
diff --git a/internal/blockchain/upgrade_test.go b/internal/blockchain/upgrade_test.go
index 23d60aa2..1df91c4d 100644
--- a/internal/blockchain/upgrade_test.go
+++ b/internal/blockchain/upgrade_test.go
@@ -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)
diff --git a/internal/blockchain/utxoio_test.go b/internal/blockchain/utxoio_test.go
index e671302b..80304a8a 100644
--- a/internal/blockchain/utxoio_test.go
+++ b/internal/blockchain/utxoio_test.go
@@ -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
@@ -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
@@ -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