Skip to content

Commit 14a8f8c

Browse files
committed
Update docs for errors
1 parent 0684ec7 commit 14a8f8c

15 files changed

+259
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local status, err = pcall(function()
2+
box.error('CustomConnectionError', '%s cannot connect to the port %u', 'client', 8080)
3+
--[[
4+
---
5+
- error: client cannot connect to the port 8080
6+
...
7+
--]]
8+
end)
9+
10+
-- Tests
11+
local luatest = require('luatest')
12+
local test_group = luatest.group()
13+
test_group.test_error_is_raised = function()
14+
luatest.assert_equals(err:unpack().type, 'CustomConnectionError')
15+
luatest.assert_equals(err:unpack().message, 'client cannot connect to the port 8080')
16+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local status, err = pcall(function()
2+
box.error('CustomConnectionError', 'cannot connect to the given port')
3+
--[[
4+
---
5+
- error: cannot connect to the given port
6+
...
7+
--]]
8+
end)
9+
10+
-- Tests
11+
local luatest = require('luatest')
12+
local test_group = luatest.group()
13+
test_group.test_error_is_raised = function()
14+
luatest.assert_equals(err:unpack().type, 'CustomConnectionError')
15+
luatest.assert_equals(err:unpack().message, 'cannot connect to the given port')
16+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local status, err = pcall(function()
2+
box.error { code = 500, reason = 'Internal server error', type = 'CustomInternalError' }
3+
--[[
4+
---
5+
- error: Internal server error
6+
...
7+
--]]
8+
end)
9+
10+
-- Tests
11+
local luatest = require('luatest')
12+
local test_group = luatest.group()
13+
test_group.test_error_is_raised = function()
14+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
15+
luatest.assert_equals(err:unpack().message, 'Internal server error')
16+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local status, err = pcall(function()
2+
box.error { code = 500, reason = 'Custom server error' }
3+
--[[
4+
---
5+
- error: Custom server error
6+
...
7+
--]]
8+
end)
9+
10+
-- Tests
11+
local luatest = require('luatest')
12+
local test_group = luatest.group()
13+
test_group.test_error_is_raised = function()
14+
luatest.assert_equals(err:unpack().message, 'Custom server error')
15+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local status, err = pcall(function()
2+
local custom_error = box.error.new('CustomInternalError', 'Internal server error')
3+
4+
box.error(custom_error)
5+
--[[
6+
---
7+
- error: Internal server error
8+
...
9+
--]]
10+
end)
11+
12+
-- Tests
13+
local luatest = require('luatest')
14+
local test_group = luatest.group()
15+
test_group.test_error_is_raised = function()
16+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
17+
luatest.assert_equals(err:unpack().message, 'Internal server error')
18+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local status, err = pcall(function()
2+
local custom_error = box.error.new({ code = 500, reason = 'Internal server error', type = 'CustomInternalError' })
3+
4+
box.error(custom_error)
5+
--[[
6+
---
7+
- error: Internal server error
8+
...
9+
--]]
10+
end)
11+
12+
-- Tests
13+
local luatest = require('luatest')
14+
local test_group = luatest.group()
15+
test_group.test_error_is_raised = function()
16+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
17+
luatest.assert_equals(err:unpack().message, 'Internal server error')
18+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local status, err = pcall(function()
2+
local custom_error = box.error.new(box.error.CREATE_SPACE, 'my_space', 'the space already exists')
3+
4+
box.error(custom_error)
5+
--[[
6+
---
7+
- error: 'Failed to create space ''my_space'': the space already exists'
8+
...
9+
--]]
10+
end)
11+
12+
-- Tests
13+
local luatest = require('luatest')
14+
local test_group = luatest.group()
15+
test_group.test_tarantool_error_is_raised = function()
16+
luatest.assert_equals(err:unpack().message, "Failed to create space 'my_space': the space already exists")
17+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local status, err = pcall(function()
2+
local custom_error = box.error.new(box.error.NO_SUCH_USER, 'John')
3+
4+
box.error(custom_error)
5+
--[[
6+
---
7+
- error: User 'John' is not found
8+
...
9+
--]]
10+
end)
11+
12+
-- Tests
13+
local luatest = require('luatest')
14+
local test_group = luatest.group()
15+
test_group.test_tarantool_error_is_raised = function()
16+
luatest.assert_equals(err:unpack().message, "User 'John' is not found")
17+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local status, err = pcall(function()
2+
box.error(box.error.CREATE_SPACE, 'my_space', 'the space already exists')
3+
--[[
4+
---
5+
- error: 'Failed to create space ''my_space'': the space already exists'
6+
...
7+
--]]
8+
end)
9+
10+
-- Tests
11+
local luatest = require('luatest')
12+
local test_group = luatest.group()
13+
test_group.test_tarantool_error_is_raised = function()
14+
luatest.assert_equals(err:unpack().message, "Failed to create space 'my_space': the space already exists")
15+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local status, err = pcall(function()
2+
box.error(box.error.NO_SUCH_USER, 'John')
3+
--[[
4+
---
5+
- error: User 'John' is not found
6+
...
7+
--]]
8+
end)
9+
10+
-- Tests
11+
local luatest = require('luatest')
12+
local test_group = luatest.group()
13+
test_group.test_tarantool_error_is_raised = function()
14+
luatest.assert_equals(err:unpack().message, "User 'John' is not found")
15+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
local status, err = pcall(function()
2+
-- Create two errors --
3+
local error1 = box.error.new({ code = 500, reason = 'Custom error 1' })
4+
local error2 = box.error.new({ code = 505, reason = 'Custom error 2' })
5+
6+
-- Raise the first error --
7+
box.error(error1)
8+
--[[
9+
---
10+
- error: Custom error 1
11+
...
12+
--]]
13+
14+
-- Get the last error --
15+
box.error.last()
16+
--[[
17+
---
18+
- Custom error 1
19+
...
20+
--]]
21+
22+
-- Set the second error as the last error --
23+
box.error.set(error2)
24+
--[[
25+
---
26+
...
27+
--]]
28+
29+
-- Get the last error --
30+
box.error.last()
31+
--[[
32+
---
33+
- Custom error 2
34+
...
35+
--]]
36+
end)
37+
38+
-- Tests
39+
local luatest = require('luatest')
40+
local test_group = luatest.group()
41+
test_group.test_error_is_raised = function()
42+
luatest.assert_equals(status, false)
43+
luatest.assert_equals(err:unpack().message, 'Custom error 1')
44+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
local status, err = pcall(function()
2+
-- Create an error --
3+
local custom_error = box.error.new({ code = 500, reason = 'Internal server error', type = 'CustomInternalError' })
4+
5+
-- Raise the error --
6+
box.error(custom_error)
7+
--[[
8+
---
9+
- error: Internal server error
10+
...
11+
--]]
12+
13+
-- Get error details --
14+
box.error.last():unpack()
15+
--[[
16+
---
17+
- code: 500
18+
base_type: CustomError
19+
type: CustomInternalError
20+
custom_type: CustomInternalError
21+
message: Internal server error
22+
trace:
23+
- file: '[string "custom_error = box.error.new({ code = 500, re..."]'
24+
line: 1
25+
...
26+
--]]
27+
28+
-- Clear the errors --
29+
box.error.clear()
30+
--[[
31+
---
32+
...
33+
--]]
34+
box.error.last()
35+
--[[
36+
---
37+
- null
38+
...
39+
--]]
40+
end)
41+
42+
-- Tests
43+
local luatest = require('luatest')
44+
local test_group = luatest.group()
45+
test_group.test_error_is_raised = function()
46+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
47+
luatest.assert_equals(err:unpack().message, 'Internal server error')
48+
end

doc/reference/reference_lua/box_error/error.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ box.error()
2121

2222
Throw an error. This method emulates a request error, with text based on one
2323
of the pre-defined Tarantool errors defined in the file `errcode.h
24-
<https://github.com/tarantool/tarantool/blob/2.1/src/box/errcode.h>`_ in
24+
<https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h>`_ in
2525
the source tree. Lua constants which correspond to those Tarantool errors are
2626
defined as members of ``box.error``, for example ``box.error.NO_SUCH_USER == 45``.
2727

doc/reference/reference_lua/errcodes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ more descriptive than error codes, are not present in server responses. The actu
99
message may contain a filename, a detailed reason or operating system error code.
1010
All such messages, however, are logged in the error log. Below are general
1111
descriptions of some popular codes. A complete list of errors can be found in file
12-
`errcode.h <https://github.com/tarantool/tarantool/blob/master/src/box/error.h>`_ in the source tree.
12+
`errcode.h <https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h>`_ in the source tree.
1313

1414
.. container:: table
1515

locale/ru/LC_MESSAGES/reference/reference_lua/box_error/error.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ msgstr "(целое число) числовой код ошибки, задае
2929
msgid ""
3030
"Throw an error. This method emulates a request error, with text based on one"
3131
" of the pre-defined Tarantool errors defined in the file `errcode.h "
32-
"<https://github.com/tarantool/tarantool/blob/2.1/src/box/errcode.h>`_ in the"
32+
"<https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h>`_ in the"
3333
" source tree. Lua constants which correspond to those Tarantool errors are "
3434
"defined as members of ``box.error``, for example ``box.error.NO_SUCH_USER =="
3535
" 45``."
3636
msgstr ""
3737
"Выдача ошибки. Моделирование ошибки запроса с текстом на основе одной из "
3838
"ошибок Tarantool, заданных в файле `errcode.h "
39-
"<https://github.com/tarantool/tarantool/blob/2.1/src/box/errcode.h>`_ в "
39+
"<https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h>`_ в "
4040
"исходном дереве. Lua-постоянные, которые соответствуют этим ошибкам в "
4141
"Tarantool, определяются как элементы ``box.error``, например "
4242
"``box.error.NO_SUCH_USER == 45``."

0 commit comments

Comments
 (0)