github.com/bobyang007/helper@v1.1.3/reflecth/op-errors.go (about) 1 package reflecth 2 3 import ( 4 "errors" 5 "github.com/bobyang007/helper/strconvh" 6 "go/token" 7 "reflect" 8 ) 9 10 func opSError(desc string) error { 11 return errors.New("invalid operation: " + desc) 12 } 13 func binaryOpSError(x, op, y, reason string) error { 14 return opSError(x + " " + op + " " + y + ": " + reason) 15 } 16 func unaryOpError(x reflect.Value, op token.Token) error { 17 return opSError(op.String() + " " + x.Type().String()) 18 } 19 func unaryOpInvalidReceiverError(x reflect.Value, op token.Token) error { 20 return opSError(op.String() + " " + x.Type().String() + ": receive from non-chan type " + x.Type().String()) 21 } 22 func unaryOpReceiveFromSendOnlyError(x reflect.Value, op token.Token) error { 23 return opSError(op.String() + " " + x.Type().String() + ": receive from send-only type " + x.Type().String()) 24 } 25 func binaryOpError(x reflect.Value, op token.Token, y reflect.Value, reason string) error { 26 return binaryOpSError(x.String(), op.String(), y.String(), reason) 27 } 28 func shiftOpInvalidShiftTypeError(x reflect.Value, op token.Token, s uint) error { 29 return binaryOpSError(x.String(), op.String(), strconvh.FormatUint(s), "shift of type "+x.Type().String()) 30 } 31 func binaryOpInvalidOperatorSError(x, op, y string) error { 32 return binaryOpSError(x, op, y, "invalid operator") 33 } 34 func binaryOpInvalidOperatorError(x reflect.Value, op token.Token, y reflect.Value) error { 35 return binaryOpInvalidOperatorSError(x.String(), op.String(), y.String()) 36 } 37 func shiftOpInvalidOperatorError(x reflect.Value, op token.Token, s uint) error { 38 return binaryOpInvalidOperatorSError(x.String(), op.String(), strconvh.FormatUint(s)) 39 } 40 func binaryOpIncomparableError(x reflect.Value, op token.Token, y reflect.Value) error { 41 return binaryOpError(x, op, y, "incomparable types "+x.Type().String()+" and "+y.Type().String()) 42 } 43 func binaryOpUnorderedError(x reflect.Value, op token.Token, y reflect.Value) error { 44 return binaryOpError(x, op, y, "unordered types "+x.Type().String()+" and "+y.Type().String()) 45 } 46 func binaryOpMismatchTypesError(x reflect.Value, op token.Token, y reflect.Value) error { 47 return binaryOpError(x, op, y, "mismatched types "+x.Type().String()+" and "+y.Type().String()) 48 } 49 func invBinOpTypesInvalError(x reflect.Value, op token.Token, y reflect.Value) error { 50 return binaryOpError(x, op, y, "invalid types "+x.Type().String()+" and/or "+y.Type().String()) 51 }