1
0

errors.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package tengo
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. var (
  7. // ErrStackOverflow is a stack overflow error.
  8. ErrStackOverflow = errors.New("stack overflow")
  9. // ErrObjectAllocLimit is an objects allocation limit error.
  10. ErrObjectAllocLimit = errors.New("object allocation limit exceeded")
  11. // ErrIndexOutOfBounds is an error where a given index is out of the
  12. // bounds.
  13. ErrIndexOutOfBounds = errors.New("index out of bounds")
  14. // ErrInvalidIndexType represents an invalid index type.
  15. ErrInvalidIndexType = errors.New("invalid index type")
  16. // ErrInvalidIndexValueType represents an invalid index value type.
  17. ErrInvalidIndexValueType = errors.New("invalid index value type")
  18. // ErrInvalidIndexOnError represents an invalid index on error.
  19. ErrInvalidIndexOnError = errors.New("invalid index on error")
  20. // ErrInvalidOperator represents an error for invalid operator usage.
  21. ErrInvalidOperator = errors.New("invalid operator")
  22. // ErrWrongNumArguments represents a wrong number of arguments error.
  23. ErrWrongNumArguments = errors.New("wrong number of arguments")
  24. // ErrBytesLimit represents an error where the size of bytes value exceeds
  25. // the limit.
  26. ErrBytesLimit = errors.New("exceeding bytes size limit")
  27. // ErrStringLimit represents an error where the size of string value
  28. // exceeds the limit.
  29. ErrStringLimit = errors.New("exceeding string size limit")
  30. // ErrNotIndexable is an error where an Object is not indexable.
  31. ErrNotIndexable = errors.New("not indexable")
  32. // ErrNotIndexAssignable is an error where an Object is not index
  33. // assignable.
  34. ErrNotIndexAssignable = errors.New("not index-assignable")
  35. // ErrNotImplemented is an error where an Object has not implemented a
  36. // required method.
  37. ErrNotImplemented = errors.New("not implemented")
  38. // ErrInvalidRangeStep is an error where the step parameter is less than or equal to 0 when using builtin range function.
  39. ErrInvalidRangeStep = errors.New("range step must be greater than 0")
  40. )
  41. // ErrInvalidArgumentType represents an invalid argument value type error.
  42. type ErrInvalidArgumentType struct {
  43. Name string
  44. Expected string
  45. Found string
  46. }
  47. func (e ErrInvalidArgumentType) Error() string {
  48. return fmt.Sprintf("invalid type for argument '%s': expected %s, found %s",
  49. e.Name, e.Expected, e.Found)
  50. }