errors.go

 1// Package wasmruntime contains internal symbols shared between modules for error handling.
 2// Note: This is named wasmruntime to avoid conflicts with the normal go module.
 3// Note: This only imports "api" as importing "wasm" would create a cyclic dependency.
 4package wasmruntime
 5
 6var (
 7	// ErrRuntimeStackOverflow indicates that there are too many function calls,
 8	// and the Engine terminated the execution.
 9	ErrRuntimeStackOverflow = New("stack overflow")
10	// ErrRuntimeInvalidConversionToInteger indicates the Wasm function tries to
11	// convert NaN floating point value to integers during trunc variant instructions.
12	ErrRuntimeInvalidConversionToInteger = New("invalid conversion to integer")
13	// ErrRuntimeIntegerOverflow indicates that an integer arithmetic resulted in
14	// overflow value. For example, when the program tried to truncate a float value
15	// which doesn't fit in the range of target integer.
16	ErrRuntimeIntegerOverflow = New("integer overflow")
17	// ErrRuntimeIntegerDivideByZero indicates that an integer div or rem instructions
18	// was executed with 0 as the divisor.
19	ErrRuntimeIntegerDivideByZero = New("integer divide by zero")
20	// ErrRuntimeUnreachable means "unreachable" instruction was executed by the program.
21	ErrRuntimeUnreachable = New("unreachable")
22	// ErrRuntimeOutOfBoundsMemoryAccess indicates that the program tried to access the
23	// region beyond the linear memory.
24	ErrRuntimeOutOfBoundsMemoryAccess = New("out of bounds memory access")
25	// ErrRuntimeInvalidTableAccess means either offset to the table was out of bounds of table, or
26	// the target element in the table was uninitialized during call_indirect instruction.
27	ErrRuntimeInvalidTableAccess = New("invalid table access")
28	// ErrRuntimeIndirectCallTypeMismatch indicates that the type check failed during call_indirect.
29	ErrRuntimeIndirectCallTypeMismatch = New("indirect call type mismatch")
30	// ErrRuntimeUnalignedAtomic indicates that an atomic operation was made with incorrect memory alignment.
31	ErrRuntimeUnalignedAtomic = New("unaligned atomic")
32	// ErrRuntimeExpectedSharedMemory indicates that an operation was made against unshared memory when not allowed.
33	ErrRuntimeExpectedSharedMemory = New("expected shared memory")
34	// ErrRuntimeTooManyWaiters indicates that atomic.wait was called with too many waiters.
35	ErrRuntimeTooManyWaiters = New("too many waiters")
36)
37
38// Error is returned by a wasm.Engine during the execution of Wasm functions, and they indicate that the Wasm runtime
39// state is unrecoverable.
40type Error struct {
41	s string
42}
43
44func New(text string) *Error {
45	return &Error{s: text}
46}
47
48func (e *Error) Error() string {
49	return e.s
50}