github.com/movsb/taorm@v0.0.0-20201209183410-91bafb0b22a6/filter/error.go (about)

     1  package filter
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  var errSkipFilter = errors.New("filter: should skip")
     9  
    10  // UnknownMapperError implies an unknown mapper error.
    11  type UnknownMapperError struct {
    12  }
    13  
    14  func (e UnknownMapperError) Error() string {
    15  	return "insight: unknown mapper prototype"
    16  }
    17  
    18  // InvalidOrderByError implies that an order by statement is invalid.
    19  type InvalidOrderByError struct {
    20  }
    21  
    22  func (e InvalidOrderByError) Error() string {
    23  	return "insight: invalid order by"
    24  }
    25  
    26  // InvalidOperatorError reports an invalid operator.
    27  type InvalidOperatorError struct {
    28  	Name     string
    29  	Operator TokenType
    30  }
    31  
    32  func (e InvalidOperatorError) Error() string {
    33  	return fmt.Sprintf(
    34  		"insight: invalid operator for field %s: %v (expect %v)",
    35  		e.Name, e.Operator, TokenTypeEqual,
    36  	)
    37  }
    38  
    39  // StructNotRegisteredError implies that a struct type has not been registered.
    40  type StructNotRegisteredError struct {
    41  }
    42  
    43  func (e StructNotRegisteredError) Error() string {
    44  	return "insight: struct is not registered"
    45  }
    46  
    47  // EnumNotFoundError implies an enum was not found.
    48  type EnumNotFoundError struct {
    49  	enum string
    50  	key  string
    51  }
    52  
    53  // NewEnumNotFoundError news a enum not found error.
    54  func newEnumNotFoundError(enum string, key string) *EnumNotFoundError {
    55  	return &EnumNotFoundError{
    56  		enum: enum,
    57  		key:  key,
    58  	}
    59  }
    60  
    61  func (e EnumNotFoundError) Error() string {
    62  	return fmt.Sprintf(`insight: enum not found: %s["%s"]`, e.enum, e.key)
    63  }
    64  
    65  // BadConversionError implies a conversion cannot be made.
    66  type BadConversionError struct {
    67  	field string
    68  	value interface{}
    69  	from  ValueType
    70  	to    ValueType
    71  }
    72  
    73  func newBadConversionError(field string, value interface{}, from ValueType, to ValueType) *BadConversionError {
    74  	return &BadConversionError{
    75  		field: field,
    76  		value: value,
    77  		from:  from,
    78  		to:    to,
    79  	}
    80  }
    81  
    82  func (e BadConversionError) Error() string {
    83  	return fmt.Sprintf(`insight: bad conversion: cannot convert value %v from type %s to type %s for field %s`, e.value, e.from, e.to, e.field)
    84  }
    85  
    86  // SyntaxError implies a syntax error.
    87  type SyntaxError struct {
    88  	msg string
    89  }
    90  
    91  // NewSyntaxError news a syntax error.
    92  func newSyntaxError(format string, args ...interface{}) *SyntaxError {
    93  	return &SyntaxError{
    94  		msg: fmt.Sprintf(format, args...),
    95  	}
    96  }
    97  
    98  func (e SyntaxError) Error() string {
    99  	return "insight: " + e.msg
   100  }