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.
This commit is contained in:
Ryan Staudt 2021-07-22 06:05:30 -05:00 committed by Dave Collins
parent 48762d6f3c
commit da4aee08cd
2 changed files with 29 additions and 0 deletions

View File

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

View File

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