box.error()
Raise the last error.
See also: box.error.last()
Raise the error defined by error_object.
Parameters:
error_object(error_object) — an error object
Example
local custom_error = box.error.new({ code = 500,reason = 'Internal server error' })box.error(custom_error)--[[---- error: Internal server error...--]]
Raise the error defined by the specified parameters.
-
reason(string) — an error description -
code(integer) — (optional) a numeric code for this error -
type(string) — (optional) an error type
Example 1
box.error { code = 500,reason = 'Custom server error' }--[[---- error: Custom server error...--]]
Example 2: custom type
box.error { code = 500,reason = 'Internal server error',type = 'CustomInternalError' }--[[---- error: Internal server error...--]]
Raise the error defined by the specified type and description.
-
type(string) — an error type -
reason(string) — an error description -
...— description arguments
Example 1: without arguments
box.error('CustomConnectionError', 'cannot connect to the given port')--[[---- error: cannot connect to the given port...--]]
Example 2: with arguments
box.error('CustomConnectionError', '%s cannot connect to the port %u', 'client', 8080)--[[---- error: client cannot connect to the port 8080...--]]
Raise a predefined Tarantool error specified by its identifier. You can see all Tarantool errors in the errcode.h file.
-
code(number) — a pre-defined error identifier; Lua constants that correspond to those Tarantool errors are defined as members ofbox.error, for example,box.error.NO_SUCH_USER == 45 -
...— description arguments
Example 1: no arguments
box.error(box.error.READONLY)--[[---- error: Can't modify data on a read-only instance...--]]
Example 2: one argument
box.error(box.error.NO_SUCH_USER, 'John')--[[---- error: User 'John' is not found...--]]
Example 3: two arguments
box.error(box.error.CREATE_SPACE, 'my_space', 'the space already exists')--[[---- error: 'Failed to create space ''my_space'': the space already exists'...--]]