Skip to content

Commit 0f7eac6

Browse files
Change conversion of box.error to string in error message assertions
Currently, error message assertions convert `box.error` to string using `tostring`. `box.error`'s `__tostring` metamethod is currently equivalent to the `message` field of `box.error`. In scope of tarantool/tarantool#9105, we are going to increase the verbosity of `box.error` `__tostring` metamethod, and it will no longer be convenient for testing the error message. Let's replace `tostring(error)` with `error.message` usag to retain the old behaviour. Needed for tarantool/tarantool#9105
1 parent f8a1c10 commit 0f7eac6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

luatest/assertions.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,11 @@ local function _assert_error_msg_equals(stripFileAndLine, expectedMsg, func, ...
468468
end
469469
if type(expectedMsg) == "string" and type(error_msg) ~= "string" then
470470
-- table are converted to string automatically
471-
error_msg = tostring(error_msg)
471+
if type(error_msg) == 'cdata' then
472+
error_msg = error_msg.message
473+
else
474+
error_msg = tostring(error_msg)
475+
end
472476
end
473477
local differ = false
474478
if stripFileAndLine then
@@ -533,7 +537,11 @@ function M.assert_error_msg_contains(expected_partial, fn, ...)
533537
failure(failure_message, nil, 2)
534538
end
535539
if type(error_msg) ~= "string" then
536-
error_msg = tostring(error_msg)
540+
if type(error_msg) == 'cdata' then
541+
error_msg = error_msg.message
542+
else
543+
error_msg = tostring(error_msg)
544+
end
537545
end
538546
if not string.find(error_msg, expected_partial, nil, true) then
539547
error_msg, expected_partial = prettystr_pairs(error_msg, expected_partial)
@@ -555,7 +563,11 @@ function M.assert_error_msg_matches(pattern, fn, ...)
555563
failure(failure_message, nil, 2)
556564
end
557565
if type(error_msg) ~= "string" then
558-
error_msg = tostring(error_msg)
566+
if type(error_msg) == 'cdata' then
567+
error_msg = error_msg.message
568+
else
569+
error_msg = tostring(error_msg)
570+
end
559571
end
560572
if not str_match(error_msg, pattern) then
561573
pattern, error_msg = prettystr_pairs(pattern, error_msg)

0 commit comments

Comments
 (0)