From 09676f02cbf807df787dc2417c12fe1355230fad Mon Sep 17 00:00:00 2001 From: Philipp Gackstatter Date: Mon, 11 Mar 2024 16:45:15 +0800 Subject: [PATCH] Remove other unknown type errors and panic instead --- builder/transaction_builder.go | 2 +- error.go | 2 -- signed_transaction.go | 2 -- tpkg/rand_unlock.go | 3 +-- unlock.go | 6 ++---- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/builder/transaction_builder.go b/builder/transaction_builder.go index 8cd152951..1584b8e5a 100644 --- a/builder/transaction_builder.go +++ b/builder/transaction_builder.go @@ -252,7 +252,7 @@ func (b *TransactionBuilder) getStoredManaOutputAccountID(storedManaOutputIndex } default: - return iotago.EmptyAccountID, ierrors.WithMessagef(iotago.ErrUnknownOutputType, "output type %T does not support stored mana", output) + return iotago.EmptyAccountID, ierrors.Errorf("output type %s does not support stored mana", output.Type()) } return storedManaOutputAccountID, nil diff --git a/error.go b/error.go index fbe419c77..4843539f5 100644 --- a/error.go +++ b/error.go @@ -30,8 +30,6 @@ var ( var ( // ErrUTXOInputInvalid gets returned when the UTXO input is invalid. ErrUTXOInputInvalid = ierrors.New("UTXO input is invalid") - // ErrUnknownOutputType gets returned for unknown output types. - ErrUnknownOutputType = ierrors.New("unknown output type") // ErrCommitmentInputMissing gets returned when the commitment has not been provided when needed. ErrCommitmentInputMissing = ierrors.New("commitment input required with reward or BIC input") // ErrCommitmentInputReferenceInvalid gets returned when the commitment input references an invalid commitment. diff --git a/signed_transaction.go b/signed_transaction.go index 67d4b35cd..aa1949d7f 100644 --- a/signed_transaction.go +++ b/signed_transaction.go @@ -14,8 +14,6 @@ var ( ErrInputOutputBaseTokenMismatch = ierrors.New("inputs and outputs do not spend/deposit the same amount of base tokens") // ErrManaOverflow gets returned when there is an under- or overflow in Mana calculations. ErrManaOverflow = ierrors.New("under- or overflow in Mana calculations") - // ErrUnknownSignatureType gets returned for unknown signature types. - ErrUnknownSignatureType = ierrors.New("unknown signature type") // ErrInputUnlockCountMismatch gets returned when the unlock count and input count mismatch. ErrInputUnlockCountMismatch = ierrors.New("unlock count and input count mismatch") // ErrSignatureAndAddrIncompatible gets returned if an address of an input has a companion signature unlock with the wrong signature type. diff --git a/tpkg/rand_unlock.go b/tpkg/rand_unlock.go index c66aefa60..1600e4cdc 100644 --- a/tpkg/rand_unlock.go +++ b/tpkg/rand_unlock.go @@ -1,7 +1,6 @@ package tpkg import ( - "github.com/iotaledger/hive.go/ierrors" iotago "github.com/iotaledger/iota.go/v4" ) @@ -30,7 +29,7 @@ func RandUnlock(allowEmptyUnlock bool) iotago.Unlock { case iotago.UnlockEmpty: return &iotago.EmptyUnlock{} default: - panic(ierrors.Wrapf(iotago.ErrUnknownUnlockType, "type %d", unlockType)) + panic("all known unlock types should be handled above") } } diff --git a/unlock.go b/unlock.go index 12538ae54..871c9eff1 100644 --- a/unlock.go +++ b/unlock.go @@ -64,8 +64,6 @@ var ( ErrReferentialUnlockInvalid = ierrors.New("invalid referential unlock") // ErrSignatureUnlockHasNilSignature gets returned if a signature unlock contains a nil signature. ErrSignatureUnlockHasNilSignature = ierrors.New("signature is nil") - // ErrUnknownUnlockType gets returned for unknown unlock. - ErrUnknownUnlockType = ierrors.New("unknown unlock type") // ErrNestedMultiUnlock gets returned when a MultiUnlock is nested inside a MultiUnlock. ErrNestedMultiUnlock = ierrors.New("multi unlocks can't be nested") // ErrEmptyUnlockOutsideMultiUnlock gets returned when an empty unlock was not nested inside of a multi unlock. @@ -252,7 +250,7 @@ func SignaturesUniqueAndReferenceUnlocksValidator(api API) UnlockValidatorFunc { continue default: - return ierrors.WithMessagef(ErrUnknownUnlockType, "unlock at index %d.%d is of unknown type %T", index, subIndex, subUnlock) + panic("all known unlock types should be handled above") } } seenMultiUnlocks[uint16(index)] = struct{}{} @@ -262,7 +260,7 @@ func SignaturesUniqueAndReferenceUnlocksValidator(api API) UnlockValidatorFunc { return ierrors.WithMessagef(ErrEmptyUnlockOutsideMultiUnlock, "unlock at index %d is invalid", index) default: - return ierrors.WithMessagef(ErrUnknownUnlockType, "unlock at index %d is of unknown type %T", index, unlock) + panic("all known unlock types should be handled above") } return nil