Skip to content
Snippets Groups Projects
Commit ee087472 authored by Nikolay Shirokovskiy's avatar Nikolay Shirokovskiy Committed by Serge Petrenko
Browse files

error: hide redundant fields of box.error.unpack()

Closes #9101

@TarantoolBot document
Title: hide redundant fields of box.error.unpack()

Do not show redundant fields of box.error.unpack(). These are `base_type`,
`custom_type` and `code` if the latter is 0.

New behaviour is available if `box_error_unpack_type_and_code` compat
option is 'new'. Default value is 'old` currently.

(The https://tarantool.io/compat/box_error_unpack_type_and_code is
to be added.)
parent d7490305
No related branches found
No related tags found
No related merge requests found
## feature/box
* Hide redundant fields from `box.error.unpack()` if
the `box_error_unpack_type_and_code` compat option is set to 'new'.
The default behaviour is 'old' (gh-9101).
......@@ -2351,6 +2351,12 @@ return schema.new('instance_config', schema.record({
}, {
default = 'new',
}),
box_error_unpack_type_and_code = schema.enum({
'old',
'new',
}, {
default = 'old',
}),
}),
}, {
-- This kind of validation cannot be implemented as the
......
......@@ -111,6 +111,14 @@ used as an error indicator in the box C API.
https://tarantool.io/compat/box_space_max
]]
local BOX_ERROR_UNPACK_TYPE_AND_CODE_BRIEF = [[
Whether to show redundant fields in box.error.unpack(). The new behaviour
is not to show 'base_type' and 'custom_type' fields. 'code' field is also not
shown if it is 0. Note that 'base_type' is still accessible for error object.
https://tarantool.io/compat/box_error_unpack_type_and_code
]]
-- Returns an action callback that toggles a tweak.
local function tweak_action(tweak_name, old_tweak_value, new_tweak_value)
return function(is_new)
......@@ -210,6 +218,12 @@ local options = {
brief = BOX_SPACE_MAX_BRIEF,
action = tweak_action('BOX_SPACE_MAX', 2147483647, 2147483646)
},
box_error_unpack_type_and_code = {
default = 'old',
obsolete = nil,
brief = BOX_ERROR_UNPACK_TYPE_AND_CODE_BRIEF,
action = function() end
},
}
-- Array with option names in order of addition.
......
......@@ -2,6 +2,7 @@
local ffi = require('ffi')
local msgpack = require('msgpack')
local compat = require('compat')
local mp_decode = msgpack.decode_unchecked
......@@ -147,6 +148,14 @@ local function error_unpack(err)
local f = fields[i]
result[ffi.string(f._name)] = mp_decode(f._data)
end
-- Hide redundant fields from unpack output (gh-9101).
if compat.box_error_unpack_type_and_code:is_new() then
result.custom_type = nil
result.base_type = nil
if result.code == 0 then
result.code = nil
end
end
return result
end
......
local t = require('luatest')
local compat = require('compat')
local g = t.group()
-- Test the `prev' argument to the table constructor of `box.error.new'
......@@ -138,3 +140,32 @@ g.test_payload_inheritance = function()
t.assert_equals(e3.bar, 33) -- Inherited from e2.
t.assert_equals(e3.baz, 55) -- Own payload field.
end
g.after_test('test_unpack', function()
compat.box_error_unpack_type_and_code = 'default'
end)
-- Test that redundant fields of error:unpack() are not serialized (gh-9101).
g.test_unpack = function()
t.assert(compat.box_error_unpack_type_and_code.default, 'old')
compat.box_error_unpack_type_and_code = 'old'
local u = box.error.new{type = 'MyError', reason = 'foobar'}:unpack()
t.assert_equals(u.base_type, 'CustomError')
t.assert_equals(u.custom_type, 'MyError')
t.assert_equals(u.code, 0)
u = box.error.new(box.error.UNSUPPORTED, 'foo', 'bar'):unpack()
t.assert_equals(u.base_type, 'ClientError')
t.assert_equals(u.custom_type, nil)
t.assert_equals(type(u.code), 'number')
compat.box_error_unpack_type_and_code = 'new'
u = box.error.new{type = 'MyError', reason = 'foobar'}:unpack()
t.assert_equals(u.base_type, nil)
t.assert_equals(u.custom_type, nil)
t.assert_equals(u.code, nil)
u = box.error.new(box.error.UNSUPPORTED, 'foo', 'bar'):unpack()
t.assert_equals(u.base_type, nil)
t.assert_equals(u.custom_type, nil)
t.assert_equals(type(u.code), 'number')
end
......@@ -341,6 +341,7 @@ g.test_defaults = function()
box_space_execute_priv = 'new',
box_tuple_extension = 'new',
box_space_max = 'new',
box_error_unpack_type_and_code = 'old',
},
}
local res = cluster_config:apply_default({})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment