github.com/aergoio/aergo@v1.3.1/contract/errors.go (about)

     1  /**
     2   *  @file
     3   *  @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package contract
     7  
     8  type ErrSystem interface {
     9  	System() bool
    10  }
    11  
    12  func isSystemError(err error) bool {
    13  	sErr, ok := err.(ErrSystem)
    14  	return ok && sErr.System()
    15  }
    16  
    17  type vmStartError struct{}
    18  
    19  func newVmStartError() error {
    20  	return &vmStartError{}
    21  }
    22  
    23  func (e *vmStartError) Error() string {
    24  	return "cannot start a VM"
    25  }
    26  
    27  func (e *vmStartError) System() bool {
    28  	return e != nil
    29  }
    30  
    31  type DbSystemError struct {
    32  	error
    33  }
    34  
    35  func newDbSystemError(e error) error {
    36  	return &DbSystemError{e}
    37  }
    38  
    39  func (e *DbSystemError) System() bool {
    40  	return e != nil
    41  }
    42  
    43  type VmSystemError struct {
    44  	error
    45  }
    46  
    47  func newVmSystemError(e error) error {
    48  	return &VmSystemError{e}
    49  }
    50  
    51  func (e *VmSystemError) System() bool {
    52  	return e != nil
    53  }
    54  
    55  type ErrRuntime interface {
    56  	Runtime() bool
    57  }
    58  
    59  func IsRuntimeError(err error) bool {
    60  	rErr, ok := err.(ErrRuntime)
    61  	return ok && rErr.Runtime()
    62  }
    63  
    64  type vmError struct {
    65  	error
    66  }
    67  
    68  func newVmError(err error) error {
    69  	return &vmError{err}
    70  }
    71  
    72  func (e *vmError) Runtime() bool {
    73  	return e != nil
    74  }
    75  
    76  //Governance Errors
    77  
    78  type ErrGovEnt interface {
    79  	GovEnt() bool
    80  }
    81  
    82  type GovEntErr struct {
    83  	error
    84  }
    85  
    86  func NewGovEntErr(e error) error {
    87  	return &GovEntErr{e}
    88  }
    89  
    90  func (e *GovEntErr) GovEnt() bool {
    91  	return e != nil
    92  }
    93  
    94  func (e *GovEntErr) Runtime() bool {
    95  	return e != nil
    96  }
    97  
    98  func IsGovEntErr(err error) bool {
    99  	rErr, ok := err.(ErrGovEnt)
   100  	return ok && rErr.GovEnt()
   101  }