github.com/karalabe/go-ethereum@v0.8.5/core/error.go (about) 1 package core 2 3 import ( 4 "errors" 5 "fmt" 6 "math/big" 7 ) 8 9 var ( 10 BlockNumberErr = errors.New("block number invalid") 11 BlockFutureErr = errors.New("block time is in the future") 12 ) 13 14 // Parent error. In case a parent is unknown this error will be thrown 15 // by the block manager 16 type ParentErr struct { 17 Message string 18 } 19 20 func (err *ParentErr) Error() string { 21 return err.Message 22 } 23 24 func ParentError(hash []byte) error { 25 return &ParentErr{Message: fmt.Sprintf("Block's parent unkown %x", hash)} 26 } 27 28 func IsParentErr(err error) bool { 29 _, ok := err.(*ParentErr) 30 31 return ok 32 } 33 34 type UncleErr struct { 35 Message string 36 } 37 38 func (err *UncleErr) Error() string { 39 return err.Message 40 } 41 42 func UncleError(str string) error { 43 return &UncleErr{Message: str} 44 } 45 46 func IsUncleErr(err error) bool { 47 _, ok := err.(*UncleErr) 48 49 return ok 50 } 51 52 // Block validation error. If any validation fails, this error will be thrown 53 type ValidationErr struct { 54 Message string 55 } 56 57 func (err *ValidationErr) Error() string { 58 return err.Message 59 } 60 61 func ValidationError(format string, v ...interface{}) *ValidationErr { 62 return &ValidationErr{Message: fmt.Sprintf(format, v...)} 63 } 64 65 func IsValidationErr(err error) bool { 66 _, ok := err.(*ValidationErr) 67 68 return ok 69 } 70 71 type NonceErr struct { 72 Message string 73 Is, Exp uint64 74 } 75 76 func (err *NonceErr) Error() string { 77 return err.Message 78 } 79 80 func NonceError(is, exp uint64) *NonceErr { 81 return &NonceErr{Message: fmt.Sprintf("Nonce err. Is %d, expected %d", is, exp), Is: is, Exp: exp} 82 } 83 84 func IsNonceErr(err error) bool { 85 _, ok := err.(*NonceErr) 86 87 return ok 88 } 89 90 type OutOfGasErr struct { 91 Message string 92 } 93 94 func OutOfGasError() *OutOfGasErr { 95 return &OutOfGasErr{Message: "Out of gas"} 96 } 97 func (self *OutOfGasErr) Error() string { 98 return self.Message 99 } 100 101 func IsOutOfGasErr(err error) bool { 102 _, ok := err.(*OutOfGasErr) 103 104 return ok 105 } 106 107 type TDError struct { 108 a, b *big.Int 109 } 110 111 func (self *TDError) Error() string { 112 return fmt.Sprintf("incoming chain has a lower or equal TD (%v <= %v)", self.a, self.b) 113 } 114 func IsTDError(e error) bool { 115 _, ok := e.(*TDError) 116 return ok 117 } 118 119 type KnownBlockError struct { 120 number *big.Int 121 hash []byte 122 } 123 124 func (self *KnownBlockError) Error() string { 125 return fmt.Sprintf("block %v already known (%x)", self.number, self.hash[0:4]) 126 } 127 func IsKnownBlockErr(e error) bool { 128 _, ok := e.(*KnownBlockError) 129 return ok 130 }