-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patherrors.go
84 lines (64 loc) · 2.91 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2020-2023 Ozan Hacıbekiroğlu.
// Use of this source code is governed by a MIT License
// that can be found in the LICENSE file.
package ugo
import (
"fmt"
)
var (
// ErrSymbolLimit represents a symbol limit error which is returned by
// Compiler when number of local symbols exceeds the symbo limit for
// a function that is 256.
ErrSymbolLimit = &Error{
Name: "SymbolLimitError",
Message: "number of local symbols exceeds the limit",
}
// ErrStackOverflow represents a stack overflow error.
ErrStackOverflow = &Error{Name: "StackOverflowError"}
// ErrVMAborted represents a VM aborted error.
ErrVMAborted = &Error{Name: "VMAbortedError"}
// ErrWrongNumArguments represents a wrong number of arguments error.
ErrWrongNumArguments = &Error{Name: "WrongNumberOfArgumentsError"}
// ErrInvalidOperator represents an error for invalid operator usage.
ErrInvalidOperator = &Error{Name: "InvalidOperatorError"}
// ErrIndexOutOfBounds represents an out of bounds index error.
ErrIndexOutOfBounds = &Error{Name: "IndexOutOfBoundsError"}
// ErrInvalidIndex represents an invalid index error.
ErrInvalidIndex = &Error{Name: "InvalidIndexError"}
// ErrNotIterable is an error where an Object is not iterable.
ErrNotIterable = &Error{Name: "NotIterableError"}
// ErrNotIndexable is an error where an Object is not indexable.
ErrNotIndexable = &Error{Name: "NotIndexableError"}
// ErrNotIndexAssignable is an error where an Object is not index assignable.
ErrNotIndexAssignable = &Error{Name: "NotIndexAssignableError"}
// ErrNotCallable is an error where Object is not callable.
ErrNotCallable = &Error{Name: "NotCallableError"}
// ErrNotImplemented is an error where an Object has not implemented a required method.
ErrNotImplemented = &Error{Name: "NotImplementedError"}
// ErrZeroDivision is an error where divisor is zero.
ErrZeroDivision = &Error{Name: "ZeroDivisionError"}
// ErrType represents a type error.
ErrType = &Error{Name: "TypeError"}
)
// NewOperandTypeError creates a new Error from ErrType.
func NewOperandTypeError(token, leftType, rightType string) *Error {
return ErrType.NewError(
fmt.Sprintf("unsupported operand types for '%s': '%s' and '%s'",
token, leftType, rightType))
}
// NewArgumentTypeError creates a new Error from ErrType.
func NewArgumentTypeError(pos, expectType, foundType string) *Error {
return ErrType.NewError(
fmt.Sprintf("invalid type for argument '%s': expected %s, found %s",
pos, expectType, foundType))
}
// NewIndexTypeError creates a new Error from ErrType.
func NewIndexTypeError(expectType, foundType string) *Error {
return ErrType.NewError(
fmt.Sprintf("index type expected %s, found %s", expectType, foundType))
}
// NewIndexValueTypeError creates a new Error from ErrType.
func NewIndexValueTypeError(expectType, foundType string) *Error {
return ErrType.NewError(
fmt.Sprintf("index value type expected %s, found %s", expectType, foundType))
}