From da4aee08cd1cb7d5f53051c349bf4ff7cef4a717 Mon Sep 17 00:00:00 2001 From: Ryan Staudt Date: Thu, 22 Jul 2021 06:05:30 -0500 Subject: [PATCH] blockchain: Add UTXO backend error kinds. This adds new blockchain error kinds for the UTXO backend. Additionally, it adds a RawErr field to ContextError which contains the original error in the case where an error has been converted. --- blockchain/error.go | 25 +++++++++++++++++++++++++ blockchain/error_test.go | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/blockchain/error.go b/blockchain/error.go index 1c62fd45..224bd7f1 100644 --- a/blockchain/error.go +++ b/blockchain/error.go @@ -598,6 +598,27 @@ const ( // ErrInvalidateGenesisBlock indicates an attempt to invalidate the genesis // block which is not allowed. ErrInvalidateGenesisBlock = ErrorKind("ErrInvalidateGenesisBlock") + + // ------------------------------------------ + // Errors related to the UTXO backend. + // ------------------------------------------ + + // ErrUtxoBackend indicates that a general error was encountered when + // accessing the UTXO backend. + ErrUtxoBackend = ErrorKind("ErrUtxoBackend") + + // ErrUtxoBackendCorruption indicates that underlying data being accessed in + // the UTXO backend is corrupted. + ErrUtxoBackendCorruption = ErrorKind("ErrUtxoBackendCorruption") + + // ErrUtxoBackendNotOpen indicates that the UTXO backend was accessed before + // it was opened or after it was closed. + ErrUtxoBackendNotOpen = ErrorKind("ErrUtxoBackendNotOpen") + + // ErrUtxoBackendTxClosed indicates an attempt was made to commit or rollback + // a UTXO backend transaction that has already had one of those operations + // performed. + ErrUtxoBackendTxClosed = ErrorKind("ErrUtxoBackendTxClosed") ) // Error satisfies the error interface and prints human-readable errors. @@ -608,9 +629,13 @@ func (e ErrorKind) Error() string { // ContextError wraps an error with additional context. It has full support for // errors.Is and errors.As, so the caller can ascertain the specific wrapped // error. +// +// RawErr contains the original error in the case where an error has been +// converted. type ContextError struct { Err error Description string + RawErr error } // Error satisfies the error interface and prints human-readable errors. diff --git a/blockchain/error_test.go b/blockchain/error_test.go index a8add038..fb5a5afe 100644 --- a/blockchain/error_test.go +++ b/blockchain/error_test.go @@ -155,6 +155,10 @@ func TestErrorKindStringer(t *testing.T) { {ErrNoFilter, "ErrNoFilter"}, {ErrNoTreasuryBalance, "ErrNoTreasuryBalance"}, {ErrInvalidateGenesisBlock, "ErrInvalidateGenesisBlock"}, + {ErrUtxoBackend, "ErrUtxoBackend"}, + {ErrUtxoBackendCorruption, "ErrUtxoBackendCorruption"}, + {ErrUtxoBackendNotOpen, "ErrUtxoBackendNotOpen"}, + {ErrUtxoBackendTxClosed, "ErrUtxoBackendTxClosed"}, } t.Logf("Running %d tests", len(tests))