github.com/onflow/flow-go@v0.33.17/fvm/evm/types/errors.go (about)

     1  package types
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  var (
     9  	// ErrAccountDoesNotExist is returned when evm account doesn't exist
    10  	ErrAccountDoesNotExist = errors.New("account does not exist")
    11  
    12  	// ErrInsufficientBalance is returned when evm account doesn't have enough balance
    13  	ErrInsufficientBalance = errors.New("insufficient balance")
    14  
    15  	// ErrInsufficientComputation is returned when not enough computation is
    16  	// left in the context of flow transaction to execute the evm operation.
    17  	ErrInsufficientComputation = errors.New("insufficient computation")
    18  
    19  	// ErrUnAuthroizedMethodCall method call, usually emited when calls are called on EOA accounts
    20  	ErrUnAuthroizedMethodCall = errors.New("unauthroized method call")
    21  
    22  	// ErrInsufficientTotalSupply is returned when flow token
    23  	// is withdraw request is there but not enough balance is on EVM vault
    24  	// this should never happen but its a saftey measure to protect Flow against EVM issues.
    25  	// TODO: we might consider this fatal
    26  	ErrInsufficientTotalSupply = errors.New("insufficient total supply")
    27  
    28  	// ErrBalanceConversion is returned conversion of balance has failed, usually
    29  	// is returned when the balance presented in attoflow has values that could
    30  	// be marginally lost on the conversion.
    31  	ErrBalanceConversion = errors.New("balance converion error")
    32  
    33  	// ErrNotImplemented is a fatal error when something is called that is not implemented
    34  	ErrNotImplemented = NewFatalError(errors.New("a functionality is called that is not implemented"))
    35  )
    36  
    37  // EVMExecutionError is a non-fatal error, returned when execution of
    38  // an evm transaction or direct call has failed.
    39  type EVMExecutionError struct {
    40  	err error
    41  }
    42  
    43  // NewEVMExecutionError returns a new EVMExecutionError
    44  func NewEVMExecutionError(rootCause error) EVMExecutionError {
    45  	return EVMExecutionError{
    46  		err: rootCause,
    47  	}
    48  }
    49  
    50  // Unwrap unwraps the underlying evm error
    51  func (err EVMExecutionError) Unwrap() error {
    52  	return err.err
    53  }
    54  
    55  func (err EVMExecutionError) Error() string {
    56  	return fmt.Sprintf("EVM execution error: %v", err.err)
    57  }
    58  
    59  // IsEVMValidationError returns true if the error or any underlying errors
    60  // is of the type EVM execution error
    61  func IsEVMExecutionError(err error) bool {
    62  	return errors.As(err, &EVMExecutionError{})
    63  }
    64  
    65  // EVMValidationError is a non-fatal error, returned when validation steps of an EVM transaction
    66  // or direct call has failed.
    67  type EVMValidationError struct {
    68  	err error
    69  }
    70  
    71  // NewEVMValidationError returns a new EVMValidationError
    72  func NewEVMValidationError(rootCause error) EVMValidationError {
    73  	return EVMValidationError{
    74  		err: rootCause,
    75  	}
    76  }
    77  
    78  // Unwrap unwraps the underlying evm error
    79  func (err EVMValidationError) Unwrap() error {
    80  	return err.err
    81  }
    82  
    83  func (err EVMValidationError) Error() string {
    84  	return fmt.Sprintf("EVM validation error: %v", err.err)
    85  }
    86  
    87  // IsEVMValidationError returns true if the error or any underlying errors
    88  // is of the type EVM validation error
    89  func IsEVMValidationError(err error) bool {
    90  	return errors.As(err, &EVMValidationError{})
    91  }
    92  
    93  // StateError is a non-fatal error, returned when a state operation
    94  // has failed (e.g. reaching storage interaction limit)
    95  type StateError struct {
    96  	err error
    97  }
    98  
    99  // NewStateError returns a new StateError
   100  func NewStateError(rootCause error) StateError {
   101  	return StateError{
   102  		err: rootCause,
   103  	}
   104  }
   105  
   106  // Unwrap unwraps the underlying evm error
   107  func (err StateError) Unwrap() error {
   108  	return err.err
   109  }
   110  
   111  func (err StateError) Error() string {
   112  	return fmt.Sprintf("state error: %v", err.err)
   113  }
   114  
   115  // IsAStateError returns true if the error or any underlying errors
   116  // is of the type EVM validation error
   117  func IsAStateError(err error) bool {
   118  	return errors.As(err, &StateError{})
   119  }
   120  
   121  // FatalError is used for any error that is not user related and something
   122  // unusual has happend. Usually we stop the node when this happens
   123  // given it might have a non-deterministic root.
   124  type FatalError struct {
   125  	err error
   126  }
   127  
   128  // NewFatalError returns a new FatalError
   129  func NewFatalError(rootCause error) FatalError {
   130  	return FatalError{
   131  		err: rootCause,
   132  	}
   133  }
   134  
   135  // Unwrap unwraps the underlying fatal error
   136  func (err FatalError) Unwrap() error {
   137  	return err.err
   138  }
   139  
   140  func (err FatalError) Error() string {
   141  	return fmt.Sprintf("fatal error: %v", err.err)
   142  }
   143  
   144  // IsAFatalError returns true if the error or underlying error
   145  // is of fatal type.
   146  func IsAFatalError(err error) bool {
   147  	return errors.As(err, &FatalError{})
   148  }
   149  
   150  // IsAInsufficientTotalSupplyError returns true if the
   151  // error type is InsufficientTotalSupplyError
   152  func IsAInsufficientTotalSupplyError(err error) bool {
   153  	return errors.Is(err, ErrInsufficientTotalSupply)
   154  }
   155  
   156  // IsAUnAuthroizedMethodCallError returns true if the error type is
   157  // UnAuthroizedMethodCallError
   158  func IsAUnAuthroizedMethodCallError(err error) bool {
   159  	return errors.Is(err, ErrUnAuthroizedMethodCall)
   160  }