github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/runner/error.go (about) 1 package runner 2 3 import ( 4 "fmt" 5 ) 6 7 type Error struct { 8 Type ErrType 9 Name string 10 } 11 12 func (e *Error) Error() string { 13 return fmt.Sprintf("task %s %s", e.Name, e.Type) 14 } 15 16 type ErrType int 17 18 const ( 19 ErrTypeNormal ErrType = iota 20 ErrTypeTimeout 21 ErrTypeInterrupt 22 ) 23 24 func (errType ErrType) String() string { 25 switch errType { 26 case ErrTypeTimeout: 27 return "timeout" 28 case ErrTypeInterrupt: 29 return "interrupt" 30 default: 31 return "failed" 32 } 33 } 34 35 func IsErrTimeout(err error) bool { 36 if e, ok := err.(*Error); ok { 37 return e.Type == ErrTypeTimeout 38 } 39 return false 40 } 41 42 func IsErrInterrupt(err error) bool { 43 if e, ok := err.(*Error); ok { 44 return e.Type == ErrTypeInterrupt 45 } 46 return false 47 }