Help us shape the future of Go! Take the 2026 Go Developer Survey

errors

package
v0.33.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
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 ExactArgs

func ExactArgs(args []object.Object, n int) object.Object

ExactArgs checks that args has exactly n elements

func ForCaller added in v0.33.0

func ForCaller(ctx context.Context, result object.Object) object.Object

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

func IsRunStop(obj object.Object) bool

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 MaxArgs

func MaxArgs(args []object.Object, n int) object.Object

MaxArgs checks that args has at most n elements

func MinArgs

func MinArgs(args []object.Object, n int) object.Object

MinArgs checks that args has at least n elements

func NewArgumentError

func NewArgumentError(got, want int) *object.Error

NewArgumentError creates an argument error, tagged TypeError so `except TypeError:` catches it (Python raises TypeError for arity).

func NewCallDepthExceededError

func NewCallDepthExceededError(max int) *object.Error

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

func NewCancelledError() *object.Error

NewCancelledError creates a cancellation error

func NewError

func NewError(format string, args ...interface{}) *object.Error

NewError creates a new error object

func NewIdentifierError

func NewIdentifierError(name string) *object.Error

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

func NewMemoryError(format string, args ...interface{}) *object.Error

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

func NewMemoryLimitStopError() *object.Error

NewMemoryLimitStopError creates the error that stops a run over its memory limit; try/except and with blocks let it through.

func NewPanicError

func NewPanicError(panicValue interface{}) *object.Error

NewPanicError creates a panic error with the panic value

func NewPermissionError added in v0.3.2

func NewPermissionError(format string, args ...interface{}) *object.Exception

NewPermissionError creates a PermissionError exception that bypasses try/except

func NewTimeoutError

func NewTimeoutError() *object.Error

NewTimeoutError creates a timeout error

func NewTypeError

func NewTypeError(expected, got string) *object.Error

NewTypeError creates a type error

func NewTypeErrorTagged added in v0.29.0

func NewTypeErrorTagged(format string, args ...interface{}) *object.Error

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

func NewValueError(format string, args ...interface{}) *object.Error

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

func NewZeroDivisionError() *object.Error

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 NoArgs

func NoArgs(args []object.Object) object.Object

NoArgs checks that args has no elements

func ParameterError

func ParameterError(name string, err object.Object) object.Object

ParameterError wraps an error with a parameter name for context

func RangeArgs

func RangeArgs(args []object.Object, min, max int) object.Object

RangeArgs checks that args has between min and max elements (inclusive)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL