Skip to content

Commit 26a164f

Browse files
committed
Update docs for errors
1 parent 0b54253 commit 26a164f

31 files changed

+1107
-324
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
local base_server_error = box.error.new({ code = 500,
4+
reason = 'Base server error',
5+
type = 'BaseServerError' })
6+
local storage_server_error = box.error.new({ code = 507,
7+
reason = 'Not enough storage',
8+
type = 'StorageServerError' })
9+
10+
base_server_error:set_prev(storage_server_error)
11+
--[[
12+
---
13+
...
14+
--]]
15+
16+
box.error(base_server_error)
17+
--[[
18+
---
19+
- error: Base server error
20+
...
21+
--]]
22+
23+
box.error.last().prev:unpack()
24+
--[[
25+
---
26+
- code: 507
27+
base_type: CustomError
28+
type: StorageServerError
29+
custom_type: StorageServerError
30+
message: Not enough storage
31+
trace:
32+
- file: '[string "storage_server_error = box.error.new({ code =..."]'
33+
line: 1
34+
...
35+
--]]
36+
-- snippet_end
37+
end)
38+
39+
-- Tests
40+
local luatest = require('luatest')
41+
local test_group = luatest.group()
42+
test_group.test_error_is_raised = function()
43+
luatest.assert_equals(err:unpack().type, 'BaseServerError')
44+
luatest.assert_equals(err:unpack().message, 'Base server error')
45+
luatest.assert_equals(err.prev:unpack().type, 'StorageServerError')
46+
luatest.assert_equals(err.prev:unpack().message, 'Not enough storage')
47+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
box.error('CustomConnectionError', '%s cannot connect to the port %u', 'client', 8080)
4+
--[[
5+
---
6+
- error: client cannot connect to the port 8080
7+
...
8+
--]]
9+
-- snippet_end
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, 'CustomConnectionError')
17+
luatest.assert_equals(err:unpack().message, 'client cannot connect to the port 8080')
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
box.error('CustomConnectionError', 'cannot connect to the given port')
4+
--[[
5+
---
6+
- error: cannot connect to the given port
7+
...
8+
--]]
9+
-- snippet_end
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, 'CustomConnectionError')
17+
luatest.assert_equals(err:unpack().message, 'cannot connect to the given port')
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
box.error { code = 500,
4+
reason = 'Internal server error',
5+
type = 'CustomInternalError' }
6+
--[[
7+
---
8+
- error: Internal server error
9+
...
10+
--]]
11+
-- snippet_end
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
box.error { code = 500,
4+
reason = 'Custom server error' }
5+
--[[
6+
---
7+
- error: Custom server error
8+
...
9+
--]]
10+
-- snippet_end
11+
end)
12+
13+
-- Tests
14+
local luatest = require('luatest')
15+
local test_group = luatest.group()
16+
test_group.test_error_is_raised = function()
17+
luatest.assert_equals(err:unpack().message, 'Custom server error')
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
local custom_error = box.error.new('CustomInternalError', 'Internal server error')
4+
5+
box.error(custom_error)
6+
--[[
7+
---
8+
- error: Internal server error
9+
...
10+
--]]
11+
-- snippet_end
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
local custom_error = box.error.new({ code = 500,
4+
reason = 'Internal server error',
5+
type = 'CustomInternalError' })
6+
7+
box.error(custom_error)
8+
--[[
9+
---
10+
- error: Internal server error
11+
...
12+
--]]
13+
-- snippet_end
14+
end)
15+
16+
-- Tests
17+
local luatest = require('luatest')
18+
local test_group = luatest.group()
19+
test_group.test_error_is_raised = function()
20+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
21+
luatest.assert_equals(err:unpack().message, 'Internal server error')
22+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
local custom_error = box.error.new({ code = 500,
4+
reason = 'Internal server error' })
5+
6+
box.error(custom_error)
7+
--[[
8+
---
9+
- error: Internal server error
10+
...
11+
--]]
12+
-- snippet_end
13+
end)
14+
15+
-- Tests
16+
local luatest = require('luatest')
17+
local test_group = luatest.group()
18+
test_group.test_error_is_raised = function()
19+
luatest.assert_equals(err:unpack().type, 'ClientError')
20+
luatest.assert_equals(err:unpack().message, 'Internal server error')
21+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
local custom_error = box.error.new(box.error.CREATE_SPACE, 'my_space', 'the space already exists')
4+
5+
box.error(custom_error)
6+
--[[
7+
---
8+
- error: 'Failed to create space ''my_space'': the space already exists'
9+
...
10+
--]]
11+
-- snippet_end
12+
end)
13+
14+
-- Tests
15+
local luatest = require('luatest')
16+
local test_group = luatest.group()
17+
test_group.test_tarantool_error_is_raised = function()
18+
luatest.assert_equals(err:unpack().message, "Failed to create space 'my_space': the space already exists")
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
local custom_error = box.error.new(box.error.NO_SUCH_USER, 'John')
4+
5+
box.error(custom_error)
6+
--[[
7+
---
8+
- error: User 'John' is not found
9+
...
10+
--]]
11+
-- snippet_end
12+
end)
13+
14+
-- Tests
15+
local luatest = require('luatest')
16+
local test_group = luatest.group()
17+
test_group.test_tarantool_error_is_raised = function()
18+
luatest.assert_equals(err:unpack().message, "User 'John' is not found")
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
box.error(box.error.CREATE_SPACE, 'my_space', 'the space already exists')
4+
--[[
5+
---
6+
- error: 'Failed to create space ''my_space'': the space already exists'
7+
...
8+
--]]
9+
-- snippet_end
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
box.error(box.error.READONLY)
4+
--[[
5+
---
6+
- error: Can't modify data on a read-only instance
7+
...
8+
--]]
9+
-- snippet_end
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, "Can't modify data on a read-only instance")
17+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
box.error(box.error.NO_SUCH_USER, 'John')
4+
--[[
5+
---
6+
- error: User 'John' is not found
7+
...
8+
--]]
9+
-- snippet_end
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
local status, err = pcall(function()
2+
-- snippet_start
3+
-- Create two errors --
4+
local error1 = box.error.new({ code = 500, reason = 'Custom error 1' })
5+
local error2 = box.error.new({ code = 505, reason = 'Custom error 2' })
6+
7+
-- Raise the first error --
8+
box.error(error1)
9+
--[[
10+
---
11+
- error: Custom error 1
12+
...
13+
--]]
14+
15+
-- Get the last error --
16+
box.error.last()
17+
--[[
18+
---
19+
- Custom error 1
20+
...
21+
--]]
22+
23+
-- Set the second error as the last error --
24+
box.error.set(error2)
25+
--[[
26+
---
27+
...
28+
--]]
29+
30+
-- Get the last error --
31+
box.error.last()
32+
--[[
33+
---
34+
- Custom error 2
35+
...
36+
--]]
37+
-- snippet_end
38+
end)
39+
40+
-- Tests
41+
local luatest = require('luatest')
42+
local test_group = luatest.group()
43+
test_group.test_error_is_raised = function()
44+
luatest.assert_equals(err:unpack().message, 'Custom error 1')
45+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
local status, err = pcall(function()
2+
-- Create an error: start
3+
local custom_error = box.error.new({ code = 500,
4+
reason = 'Internal server error',
5+
type = 'CustomInternalError' })
6+
-- Create an error: end
7+
8+
-- Raise the error: start
9+
box.error(custom_error)
10+
--[[
11+
---
12+
- error: Internal server error
13+
...
14+
--]]
15+
-- Raise the error: end
16+
17+
-- Get the last error: start
18+
box.error.last()
19+
--[[
20+
---
21+
- error: Internal server error
22+
...
23+
--]]
24+
-- Get the last error: end
25+
26+
-- Get error details: start
27+
box.error.last():unpack()
28+
--[[
29+
---
30+
- code: 500
31+
base_type: CustomError
32+
type: CustomInternalError
33+
custom_type: CustomInternalError
34+
message: Internal server error
35+
trace:
36+
- file: '[string "custom_error = box.error.new({ code = 500,..."]'
37+
line: 1
38+
...
39+
--]]
40+
-- Get error details: end
41+
42+
-- Clear the errors: start
43+
box.error.clear()
44+
--[[
45+
---
46+
...
47+
--]]
48+
box.error.last()
49+
--[[
50+
---
51+
- null
52+
...
53+
--]]
54+
-- Clear the errors: end
55+
end)
56+
57+
-- Tests
58+
local luatest = require('luatest')
59+
local test_group = luatest.group()
60+
test_group.test_error_is_raised = function()
61+
luatest.assert_equals(err:unpack().type, 'CustomInternalError')
62+
luatest.assert_equals(err:unpack().message, 'Internal server error')
63+
end

0 commit comments

Comments
 (0)