error.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package expression
  2. import (
  3. "fmt"
  4. )
  5. // InvalidParameterError is returned if invalid parameters are encountered. This
  6. // error specifically refers to situations where parameters are non-empty but
  7. // have an invalid syntax/format. The error message includes the function
  8. // that returned the error originally and the parameter type that was deemed
  9. // invalid.
  10. //
  11. // Example:
  12. //
  13. // // err is of type InvalidParameterError
  14. // _, err := expression.Name("foo..bar").BuildOperand()
  15. type InvalidParameterError struct {
  16. parameterType string
  17. functionName string
  18. }
  19. func (ipe InvalidParameterError) Error() string {
  20. return fmt.Sprintf("%s error: invalid parameter: %s", ipe.functionName, ipe.parameterType)
  21. }
  22. func newInvalidParameterError(funcName, paramType string) InvalidParameterError {
  23. return InvalidParameterError{
  24. parameterType: paramType,
  25. functionName: funcName,
  26. }
  27. }
  28. // UnsetParameterError is returned if parameters are empty and uninitialized.
  29. // This error is returned if opaque structs (ConditionBuilder, NameBuilder,
  30. // Builder, etc) are initialized outside of functions in the package, since all
  31. // structs in the package are designed to be initialized with functions.
  32. //
  33. // Example:
  34. //
  35. // // err is of type UnsetParameterError
  36. // _, err := expression.Builder{}.Build()
  37. // _, err := expression.NewBuilder().
  38. // WithCondition(expression.ConditionBuilder{}).
  39. // Build()
  40. type UnsetParameterError struct {
  41. parameterType string
  42. functionName string
  43. }
  44. func (upe UnsetParameterError) Error() string {
  45. return fmt.Sprintf("%s error: unset parameter: %s", upe.functionName, upe.parameterType)
  46. }
  47. func newUnsetParameterError(funcName, paramType string) UnsetParameterError {
  48. return UnsetParameterError{
  49. parameterType: paramType,
  50. functionName: funcName,
  51. }
  52. }