Skip to content

Commit 031d6a1

Browse files
feature: support error type
Support error type checks for box.error objects [1] (can be explicitly created in Tarantool Lua scripts since 2.4.1). 1. tarantool/tarantool#4398 Part of tarantool/tarantool#7726
1 parent ba6e85f commit 031d6a1

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- "error" type supported.
12+
913
### Fixed
1014

1115
- Fixed compatibility with LuaJIT.

checks.lua

+2
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,6 @@ function checkers.uuid_bin(arg)
347347
end
348348
end
349349

350+
add_ffi_type_checker('error', 'struct error')
351+
350352
return checks

test.lua

+33
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ if has_decimal then
618618
testdata.decimal = decimal
619619
end
620620

621+
function testdata.fn_error(arg) -- luacheck: no unused args
622+
checks('error')
623+
end
624+
625+
local has_error = (box.error ~= nil) and (box.error.new ~= nil)
626+
621627
local ret_cases = {
622628
-- fn_int64
623629
{
@@ -937,6 +943,33 @@ local ret_cases = {
937943
code = 'fn_decimal(1)',
938944
ok = false,
939945
},
946+
947+
-- fn_error
948+
{
949+
skip = not has_error,
950+
code = 'fn_error(box.error.new(box.error.UNKNOWN))',
951+
ok = true,
952+
},
953+
{
954+
skip = not has_error,
955+
code = 'fn_error(box.error.UNKNOWN)', -- It's an error code, not an error object.
956+
ok = false,
957+
},
958+
{
959+
skip = not has_error,
960+
code = 'fn_error(select(2, pcall(error, "my error")))',
961+
ok = false,
962+
},
963+
{
964+
skip = not has_error,
965+
code = 'fn_error()',
966+
ok = false,
967+
},
968+
{
969+
skip = not has_error,
970+
code = 'fn_error(1)',
971+
ok = false,
972+
},
940973
}
941974

942975
for _, case in pairs(ret_cases) do

0 commit comments

Comments
 (0)