github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/execution/errors/code.go (about) 1 package errors 2 3 import ( 4 "fmt" 5 ) 6 7 // An annotated version of the pure numeric error code 8 type Code struct { 9 Number uint32 10 Name string 11 Description string 12 } 13 14 func code(description string) *Code { 15 return &Code{Description: description} 16 } 17 18 func (c *Code) Equal(other *Code) bool { 19 if c == nil { 20 return false 21 } 22 return c.Number == other.Number 23 } 24 25 func (c *Code) ErrorCode() *Code { 26 return c 27 } 28 29 func (c *Code) Uint32() uint32 { 30 if c == nil { 31 return 0 32 } 33 return c.Number 34 } 35 36 func (c *Code) Error() string { 37 if c == nil { 38 return "" 39 } 40 return fmt.Sprintf("Error %d: %s", c.Number, c.Description) 41 } 42 43 func (c *Code) ErrorMessage() string { 44 if c == nil { 45 return "" 46 } 47 return c.Description 48 } 49 50 func GetCode(err error) *Code { 51 exception := AsException(err) 52 if exception == nil { 53 return Codes.None 54 } 55 return exception.GetCode() 56 }