runtimeerror.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package interpreter
  11. import (
  12. "errors"
  13. "fmt"
  14. "devt.de/krotik/eliasdb/eql/parser"
  15. )
  16. /*
  17. newRuntimeError creates a new RuntimeError object.
  18. */
  19. func (rt *eqlRuntimeProvider) newRuntimeError(t error, d string, node *parser.ASTNode) error {
  20. return &RuntimeError{rt.name, t, d, node, node.Token.Lline, node.Token.Lpos}
  21. }
  22. /*
  23. RuntimeError is a runtime related error
  24. */
  25. type RuntimeError struct {
  26. Source string // Name of the source which was given to the parser
  27. Type error // Error type (to be used for equal checks)
  28. Detail string // Details of this error
  29. Node *parser.ASTNode // AST Node where the error occurred
  30. Line int // Line of the error
  31. Pos int // Position of the error
  32. }
  33. /*
  34. Error returns a human-readable string representation of this error.
  35. */
  36. func (re *RuntimeError) Error() string {
  37. ret := fmt.Sprintf("EQL error in %s: %v (%v)", re.Source, re.Type, re.Detail)
  38. if re.Line != 0 {
  39. return fmt.Sprintf("%s (Line:%d Pos:%d)", ret, re.Line, re.Pos)
  40. }
  41. return ret
  42. }
  43. /*
  44. Runtime related error types
  45. */
  46. var (
  47. ErrNotARegex = errors.New("Value of operand is not a valid regex")
  48. ErrNotANumber = errors.New("Value of operand is not a number")
  49. ErrNotAList = errors.New("Value of operand is not a list")
  50. ErrInvalidConstruct = errors.New("Invalid construct")
  51. ErrUnknownNodeKind = errors.New("Unknown node kind")
  52. ErrInvalidSpec = errors.New("Invalid traversal spec")
  53. ErrInvalidWhere = errors.New("Invalid where clause")
  54. ErrInvalidColData = errors.New("Invalid column data spec")
  55. ErrEmptyTraversal = errors.New("Empty traversal")
  56. )
  57. /*
  58. ResultError is a result related error (e.g. wrong defined show clause)
  59. */
  60. type ResultError struct {
  61. Source string // Name of the source which was given to the parser
  62. Type error // Error type (to be used for equal checks)
  63. Detail string // Details of this error
  64. }
  65. /*
  66. Error returns a human-readable string representation of this error.
  67. */
  68. func (re *ResultError) Error() string {
  69. return fmt.Sprintf("EQL result error in %s: %v (%v)", re.Source, re.Type, re.Detail)
  70. }