Skip to content

Commit 161c7d1

Browse files
committed
Update docs for errors
1 parent 0684ec7 commit 161c7d1

16 files changed

+310
-4
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
local status, err = pcall(function()
2+
local base_server_error = box.error.new({ code = 500,
3+
reason = 'Base server error',
4+
type = 'BaseServerError' })
5+
local storage_server_error = box.error.new({ code = 507,
6+
reason = 'Not enough storage',
7+
type = 'StorageServerError' })
8+
9+
base_server_error:set_prev(storage_server_error)
10+
--[[
11+
---
12+
...
13+
--]]
14+
15+
box.error(base_server_error)
16+
--[[
17+
---
18+
- error: Base server error
19+
...
20+
--]]
21+
22+
box.error.last().prev:unpack()
23+
--[[
24+
---
25+
- code: 507
26+
base_type: CustomError
27+
type: StorageServerError
28+
custom_type: StorageServerError
29+
message: Not enough storage
30+
trace:
31+
- file: '[string "storage_server_error = box.error.new({ code =..."]'
32+
line: 1
33+
...
34+
--]]
35+
end)
36+
37+
-- Tests
38+
local luatest = require('luatest')
39+
local test_group = luatest.group()
40+
test_group.test_error_is_raised = function()
41+
luatest.assert_equals(err:unpack().type, 'BaseServerError')
42+
luatest.assert_equals(err:unpack().message, 'Base server error')
43+
luatest.assert_equals(err.prev:unpack().type, 'StorageServerError')
44+
luatest.assert_equals(err.prev:unpack().message, 'Not enough storage')
45+
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', '%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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local status, err = pcall(function()
2+
box.error { code = 500,
3+
reason = 'Internal server error',
4+
type = 'CustomInternalError' }
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: 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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local status, err = pcall(function()
2+
local custom_error = box.error.new({ code = 500,
3+
reason = 'Internal server error',
4+
type = 'CustomInternalError' })
5+
6+
box.error(custom_error)
7+
--[[
8+
---
9+
- error: Internal server error
10+
...
11+
--]]
12+
end)
13+
14+
-- Tests
15+
local luatest = require('luatest')
16+
local test_group = luatest.group()
17+
test_group.test_error_is_raised = function()
18+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
19+
luatest.assert_equals(err:unpack().message, 'Internal server error')
20+
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
local status, err = pcall(function()
2+
-- Create an error --
3+
local custom_error = box.error.new({ code = 500,
4+
reason = 'Internal server error',
5+
type = 'CustomInternalError' })
6+
7+
-- Raise the error --
8+
box.error(custom_error)
9+
--[[
10+
---
11+
- error: Internal server error
12+
...
13+
--]]
14+
15+
-- Get error details --
16+
box.error.last():unpack()
17+
--[[
18+
---
19+
- code: 500
20+
base_type: CustomError
21+
type: CustomInternalError
22+
custom_type: CustomInternalError
23+
message: Internal server error
24+
trace:
25+
- file: '[string "custom_error = box.error.new({ code = 500, re..."]'
26+
line: 1
27+
...
28+
--]]
29+
30+
-- Clear the errors --
31+
box.error.clear()
32+
--[[
33+
---
34+
...
35+
--]]
36+
box.error.last()
37+
--[[
38+
---
39+
- null
40+
...
41+
--]]
42+
end)
43+
44+
-- Tests
45+
local luatest = require('luatest')
46+
local test_group = luatest.group()
47+
test_group.test_error_is_raised = function()
48+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
49+
luatest.assert_equals(err:unpack().message, 'Internal server error')
50+
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)