errors.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package engine
  2. import "fmt"
  3. // Error types for better error handling and testing
  4. // AggregationError represents errors that occur during aggregation computation
  5. type AggregationError struct {
  6. Operation string
  7. Column string
  8. Cause error
  9. }
  10. func (e AggregationError) Error() string {
  11. return fmt.Sprintf("aggregation error in %s(%s): %v", e.Operation, e.Column, e.Cause)
  12. }
  13. // DataSourceError represents errors that occur when accessing data sources
  14. type DataSourceError struct {
  15. Source string
  16. Cause error
  17. }
  18. func (e DataSourceError) Error() string {
  19. return fmt.Sprintf("data source error in %s: %v", e.Source, e.Cause)
  20. }
  21. // OptimizationError represents errors that occur during query optimization
  22. type OptimizationError struct {
  23. Strategy string
  24. Reason string
  25. }
  26. func (e OptimizationError) Error() string {
  27. return fmt.Sprintf("optimization failed for %s: %s", e.Strategy, e.Reason)
  28. }
  29. // ParseError represents SQL parsing errors
  30. type ParseError struct {
  31. Query string
  32. Message string
  33. Cause error
  34. }
  35. func (e ParseError) Error() string {
  36. if e.Cause != nil {
  37. return fmt.Sprintf("SQL parse error: %s (%v)", e.Message, e.Cause)
  38. }
  39. return fmt.Sprintf("SQL parse error: %s", e.Message)
  40. }
  41. // TableNotFoundError represents table/topic not found errors
  42. type TableNotFoundError struct {
  43. Database string
  44. Table string
  45. }
  46. func (e TableNotFoundError) Error() string {
  47. if e.Database != "" {
  48. return fmt.Sprintf("table %s.%s not found", e.Database, e.Table)
  49. }
  50. return fmt.Sprintf("table %s not found", e.Table)
  51. }
  52. // ColumnNotFoundError represents column not found errors
  53. type ColumnNotFoundError struct {
  54. Table string
  55. Column string
  56. }
  57. func (e ColumnNotFoundError) Error() string {
  58. if e.Table != "" {
  59. return fmt.Sprintf("column %s not found in table %s", e.Column, e.Table)
  60. }
  61. return fmt.Sprintf("column %s not found", e.Column)
  62. }
  63. // UnsupportedFeatureError represents unsupported SQL features
  64. type UnsupportedFeatureError struct {
  65. Feature string
  66. Reason string
  67. }
  68. func (e UnsupportedFeatureError) Error() string {
  69. if e.Reason != "" {
  70. return fmt.Sprintf("feature not supported: %s (%s)", e.Feature, e.Reason)
  71. }
  72. return fmt.Sprintf("feature not supported: %s", e.Feature)
  73. }