Documentation
¶
Index ¶
- Constants
- func ExactArgs(args []object.Object, n int) object.Object
- func ForCaller(ctx context.Context, result object.Object) object.Object
- func IsRunStop(obj object.Object) bool
- func MaxArgs(args []object.Object, n int) object.Object
- func MinArgs(args []object.Object, n int) object.Object
- func NewArgumentError(got, want int) *object.Error
- func NewCallDepthExceededError(max int) *object.Error
- func NewCancelledError() *object.Error
- func NewError(format string, args ...interface{}) *object.Error
- func NewIdentifierError(name string) *object.Error
- func NewMemoryError(format string, args ...interface{}) *object.Error
- func NewMemoryLimitStopError() *object.Error
- func NewPanicError(panicValue interface{}) *object.Error
- func NewPermissionError(format string, args ...interface{}) *object.Exception
- func NewTimeoutError() *object.Error
- func NewTypeError(expected, got string) *object.Error
- func NewTypeErrorTagged(format string, args ...interface{}) *object.Error
- func NewValueError(format string, args ...interface{}) *object.Error
- func NewZeroDivisionError() *object.Error
- func NoArgs(args []object.Object) object.Object
- func ParameterError(name string, err object.Object) object.Object
- func RangeArgs(args []object.Object, min, max int) object.Object
Constants ¶
const ( ErrTimeout = "execution timeout" ErrCancelled = "execution cancelled" // ErrMemoryLimitStop stops a run that went over its memory limit. Unlike // other errors a script cannot catch or suppress it. ErrMemoryLimitStop = "memory limit exceeded" ErrDivisionByZero = "division by zero" ErrIndexOutOfRange = "index out of range" ErrKeyNotFound = "key not found" ErrTypeError = "type error" ErrArgumentError = "argument error" ErrIdentifierNotFound = "identifier not found" ErrUnknownOperator = "unknown operator" ErrImportError = "import error" ErrCallDepthExceeded = "call depth exceeded" ErrPanic = "script panic" )
Common error types
Variables ¶
This section is empty.
Functions ¶
func ForCaller ¶ added in v0.33.0
ForCaller returns a result produced by another run (a background task) for a caller to use. That run being stopped does not stop a caller whose own run is live, so its stop becomes an ordinary error the caller can catch.
func IsRunStop ¶ added in v0.33.0
IsRunStop reports whether obj is an error that ends the run it occurs in: a timeout or cancellation of the run's context, or the memory-limit stop. try/except and with blocks let these through, so a script cannot keep running after its host has stopped it.
func NewArgumentError ¶
NewArgumentError creates an argument error, tagged TypeError so `except TypeError:` catches it (Python raises TypeError for arity).
func NewCallDepthExceededError ¶
NewCallDepthExceededError creates the error for recursion past the call depth limit: a RecursionError, as Python raises, which `except RecursionError` (and RuntimeError or Exception) catches.
func NewCancelledError ¶
NewCancelledError creates a cancellation error
func NewIdentifierError ¶
NewIdentifierError creates a name-not-defined error, Python-shaped so models recognize it ("name 'x' is not defined").
func NewMemoryError ¶ added in v0.31.0
NewMemoryError creates an error that `except MemoryError` catches, for an operation that would create a value larger than the interpreter allows.
func NewMemoryLimitStopError ¶ added in v0.33.0
NewMemoryLimitStopError creates the error that stops a run over its memory limit; try/except and with blocks let it through.
func NewPanicError ¶
NewPanicError creates a panic error with the panic value
func NewPermissionError ¶ added in v0.3.2
NewPermissionError creates a PermissionError exception that bypasses try/except
func NewTypeError ¶
NewTypeError creates a type error
func NewTypeErrorTagged ¶ added in v0.29.0
NewTypeErrorTagged creates a type error tagged so that `except TypeError:` matches it — for the TypeError classes CPython raises where the generic NewTypeError(expected, got) message shape does not fit ("not enough arguments for format string", wrong value type for a % conversion, ...).
func NewValueError ¶ added in v0.20.0
NewValueError creates an error tagged so that `except ValueError:` matches it. Use it for a value that is the right type but outside the accepted domain — the maths-domain errors CPython reports as ValueError, for example. Like NewZeroDivisionError it stays an *object.Error so it propagates through the evaluator's object.IsError checks and keeps its file/line/function annotation.
func NewZeroDivisionError ¶ added in v0.20.0
NewZeroDivisionError creates a division-by-zero error tagged so that `except ZeroDivisionError:` matches it. It stays an *object.Error (not an Exception) so it propagates through the evaluator's existing object.IsError checks and keeps its file/line/function annotation.
func ParameterError ¶
ParameterError wraps an error with a parameter name for context
Types ¶
This section is empty.