Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change conversion of box.error to string in error message assertions #355

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions luatest/assertions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,18 @@ function M.assert_str_matches(value, pattern, start, final, message)
end
end

-- Convert an error object to an error message
-- @param err error object
-- @return error message
local function error_to_msg(err)
if type(err) == 'cdata' then
-- We assume that this is a `box.error` instance.
return err.message
else
return tostring(err)
end
end

local function _assert_error_msg_equals(stripFileAndLine, expectedMsg, func, ...)
local no_error, error_msg = pcall(func, ...)
if no_error then
Expand All @@ -467,8 +479,7 @@ local function _assert_error_msg_equals(stripFileAndLine, expectedMsg, func, ...
failure(failure_message, nil, 3)
end
if type(expectedMsg) == "string" and type(error_msg) ~= "string" then
-- table are converted to string automatically
error_msg = tostring(error_msg)
error_msg = error_to_msg(error_msg)
end
local differ = false
if stripFileAndLine then
Expand Down Expand Up @@ -533,7 +544,7 @@ function M.assert_error_msg_contains(expected_partial, fn, ...)
failure(failure_message, nil, 2)
end
if type(error_msg) ~= "string" then
error_msg = tostring(error_msg)
error_msg = error_to_msg(error_msg)
end
if not string.find(error_msg, expected_partial, nil, true) then
error_msg, expected_partial = prettystr_pairs(error_msg, expected_partial)
Expand All @@ -555,7 +566,7 @@ function M.assert_error_msg_matches(pattern, fn, ...)
failure(failure_message, nil, 2)
end
if type(error_msg) ~= "string" then
error_msg = tostring(error_msg)
error_msg = error_to_msg(error_msg)
end
if not str_match(error_msg, pattern) then
pattern, error_msg = prettystr_pairs(pattern, error_msg)
Expand Down
4 changes: 3 additions & 1 deletion luatest/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ end

local function exec_tail(ok, ...)
if not ok then
local _ok, res = pcall(json.decode, tostring(...))
local err = ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is new code block compatible with Tarantool 1.10?

-- net.box's eval method always throws a `box.error`.
local _ok, res = pcall(json.decode, err.message)
error(_ok and res or ..., 0)
else
return ...
Expand Down
Loading