Skip to content

Commit a748542

Browse files
test: replace tostring(error) with error.message for box.errors
`box.error`'s string conversion metamethod is currently equivalent to the `message` field of `box.error`. In scope of tarantool#9105, we are going to increase the verbosity of the string conversion metamethod, and it will no longer be suitable for testing the error message. Let's replace `tostring(error)` usage with `error.message` to retain the old behaviour. See also tarantool/luatest@xxx (WIP tarantool/luatest#355). Needed for tarantool#9105 NO_CHANGELOG=<tests change> NO_DOC=<tests change>
1 parent a12998a commit a748542

32 files changed

+98
-95
lines changed

test/app-luatest/fiber_slice_test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ g.test_fiber_slice = function()
3232
overhead = clock.monotonic() - overhead
3333
local start_time = clock.monotonic()
3434
local _, err = fib:join()
35-
t.assert_equals(tostring(err), "fiber slice is exceeded")
35+
t.assert_equals(err.message, "fiber slice is exceeded")
3636
local time_elapsed = clock.monotonic() - start_time - overhead
3737
t.assert_almost_equals(time_elapsed, expected_timeout, delta)
3838
end

test/app-luatest/http_client_test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ g.test_headers = function(cg)
485485
local headers = {[hname] = hvalue}
486486
local ok, err = pcall(http.post, http, url, nil,
487487
merge(opts, {headers = headers}))
488-
t.assert_equals({ok, tostring(err)}, {false, exp_err},
488+
t.assert_equals({ok, err.message}, {false, exp_err},
489489
'8193 KiB header: error')
490490
end
491491

test/app-tap/console.test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,21 @@ box.cfg{
133133
-- Connect to iproto console (CALL)
134134
client:write(string.format("require('console').connect('/')\n"))
135135
-- error: Connection is not established
136-
test:ok(yaml.decode(client:read(EOL))[1].error:find('not established'),
136+
test:ok(yaml.decode(client:read(EOL))[1].error.message:find('not established'),
137137
'remote network error')
138138

139139
client:write(string.format("require('console').connect('%s')\n",
140140
IPROTO_SOCKET))
141141
-- error: Execute access is denied for user 'guest' to function 'dostring
142-
test:ok(yaml.decode(client:read(EOL))[1].error:find('denied'),
142+
test:ok(yaml.decode(client:read(EOL))[1].error.message:find('denied'),
143143
'remote access denied')
144144

145145
-- create user
146146
box.schema.user.create('test', { password = 'pass' })
147147
client:write(string.format("require('console').connect('test:pass@%s')\n",
148148
IPROTO_SOCKET))
149149
-- error: Execute access denied for user 'test' to function 'dostring
150-
test:ok(yaml.decode(client:read(EOL))[1].error:find('denied'),
150+
test:ok(yaml.decode(client:read(EOL))[1].error.message:find('denied'),
151151
'remote access denied')
152152

153153
-- Add permissions to execute for `test`

test/app-tap/gh-5013-fiber-cancel.test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ fiber.yield()
2222
print(require('yaml').encode(result))
2323

2424
test:ok(result.res == false, 'expected result is false')
25-
test:ok(tostring(result.err) == 'fiber is cancelled', 'fiber cancellation should be reported')
25+
test:ok(result.err.message == 'fiber is cancelled', 'fiber cancellation should be reported')
2626
os.exit(test:check() and 0 or 1)

test/app-tap/logger.test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test:plan(119)
77

88
local function test_invalid_cfg(cfg_method, cfg, name, expected)
99
local _, err = pcall(cfg_method, cfg)
10-
test:ok(tostring(err):find(expected) ~= nil, name)
10+
test:ok(err.message:find(expected) ~= nil, name)
1111
end
1212

1313
local function test_allowed_types(cfg_method, cfg, name, allowed_types)
@@ -205,11 +205,11 @@ test_invalid_cfg(box.cfg, {log_nonblock = true},
205205
-- Test invalid values for setters
206206

207207
_, err = pcall(log.log_format, {})
208-
test:ok(tostring(err):find('should be of type string') ~= nil,
208+
test:ok(err.message:find('should be of type string') ~= nil,
209209
"invalid format setter value type")
210210

211211
_, err = pcall(log.level, {})
212-
test:ok(tostring(err):find('should be one of types number, string') ~= nil,
212+
test:ok(err.message:find('should be one of types number, string') ~= nil,
213213
"invalid format setter value type")
214214

215215
-- Change format and levels.

test/app-tap/popen.test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ local function test_trivial_echo_output(test)
9696
-- Sending a signal using a closed handle gives an error.
9797
local exp_err = 'popen: attempt to operate on a closed handle'
9898
local ok, err = pcall(ph.signal, ph, popen.signal.SIGTERM)
99-
test:is_deeply({ok, err.type, tostring(err)},
99+
test:is_deeply({ok, err.type, err.message},
100100
{false, 'IllegalParams', exp_err},
101101
'signal() on closed handle gives an error')
102102
end
@@ -247,7 +247,7 @@ local function test_read_timeout(test)
247247
-- Read and get a timeout error.
248248
local exp_err = 'timed out'
249249
local res, err = ph:read({timeout = 0.1})
250-
test:is_deeply({res, err.type, tostring(err)}, {nil, 'TimedOut', exp_err},
250+
test:is_deeply({res, err.type, err.message}, {nil, 'TimedOut', exp_err},
251251
'timeout error')
252252

253253
-- Write and read after the timeout error.

test/app-tap/uri.test.lua

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ local function test_parse(test)
9090
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
9191
u, error = uri.parse("")
9292
test:isnil(u, "invalid uri", u)
93-
test:is(tostring(error), expected_errmsg, "error message")
93+
test:is(error.message, expected_errmsg, "error message")
9494
u, error = uri.parse("://")
9595
test:isnil(u, "invalid uri", u)
96-
test:is(tostring(error), expected_errmsg, "error message")
96+
test:is(error.message, expected_errmsg, "error message")
9797
end
9898

9999
local function test_format(test)
@@ -245,13 +245,13 @@ local function test_parse_uri_query_params(test)
245245
expected_errmsg = "Default URI parameters are not allowed for single URI"
246246
u, error = uri.parse({ "/tmp/unix.sock", default_params = {q = "v"} })
247247
test:isnil(u, "invalid uri", u)
248-
test:is(tostring(error), expected_errmsg, "error message")
248+
test:is(error.message, expected_errmsg, "error message")
249249
-- Multiple URIs is not allowed in `parse` method,
250250
-- use `parse_many` instead.
251251
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
252252
u, error = uri.parse({ "/tmp/unix.sock, /tmp/unix.sock"})
253253
test:isnil(u, "invalid uri", u)
254-
test:is(tostring(error), expected_errmsg, "error message")
254+
test:is(error.message, expected_errmsg, "error message")
255255
end
256256

257257
local function test_parse_uri_set_with_query_params(test)
@@ -314,24 +314,24 @@ local function test_parse_uri_set_with_query_params(test)
314314
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
315315
uri_set , error= uri.parse_many("/tmp/unix.sock,,/tmp/unix.sock")
316316
test:isnil(uri_set, "invalid uri", uri_set)
317-
test:is(tostring(error), expected_errmsg, "error message")
317+
test:is(error.message, expected_errmsg, "error message")
318318
uri_set, error = uri.parse_many("/tmp/unix.sock, ,/tmp/unix.sock")
319319
test:isnil(uri_set, "invalid uri", uri_set)
320-
test:is(tostring(error), expected_errmsg, "error message")
320+
test:is(error.message, expected_errmsg, "error message")
321321
uri_set, error = uri.parse_many("/tmp/unix.sock,, /tmp/unix.sock")
322322
test:isnil(uri_set, "invalid uri", uri_set)
323-
test:is(tostring(error), expected_errmsg, "error message")
323+
test:is(error.message, expected_errmsg, "error message")
324324
uri_set, error = uri.parse_many("/tmp/unix.sock ,,/tmp/unix.sock")
325325
test:isnil(uri_set, "invalid uri", uri_set)
326-
test:is(tostring(error), expected_errmsg, "error message")
326+
test:is(error.message, expected_errmsg, "error message")
327327

328328

329329
-- Check that we can't parse string with multiple URIs,
330330
-- using old method.
331331
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
332332
local u, error = uri.parse("/tmp/unix.sock, /tmp/unix.sock")
333333
test:isnil(u, "invalid uri", u)
334-
test:is(tostring(error), expected_errmsg, "error message")
334+
test:is(error.message, expected_errmsg, "error message")
335335
end
336336

337337
local function test_parse_uri_set_from_lua_table(test)
@@ -575,75 +575,75 @@ local function test_parse_invalid_uri_set_from_lua_table(test)
575575
expected_errmsg = "Incorrect type for URI: should be string, number or table"
576576
uri_set, error = uri.parse_many(function() end)
577577
test:isnil(uri_set, "invalid uri", uri_set)
578-
test:is(tostring(error), expected_errmsg, "error message")
578+
test:is(error.message, expected_errmsg, "error message")
579579
-- Invalid type of value for numerical key
580580
expected_errmsg = "Incorrect type for URI: should be string, number or table"
581581
uri_set, error = uri.parse_many({"/tmp/unix.sock", function() end})
582582
test:isnil(uri_set, "invalid uri", uri_set)
583-
test:is(tostring(error), expected_errmsg, "error message")
583+
test:is(error.message, expected_errmsg, "error message")
584584
-- Invalid type of value for string keys
585585
expected_errmsg = "Invalid URI table: expected " ..
586586
"{uri = string, params = table}" .. " or " ..
587587
"{string, params = table}"
588588
uri_set, error = uri.parse_many({"/tmp/unix.sock", uri = function() end})
589589
test:isnil(uri_set, "invalid uri", uri_set)
590-
test:is(tostring(error), expected_errmsg, "error message")
590+
test:is(error.message, expected_errmsg, "error message")
591591
expected_errmsg = "Incorrect type for URI parameters: should be a table"
592592
uri_set, error = uri.parse_many({"/tmp/unix.sock", params = function() end})
593593
test:isnil(uri_set, "invalid uri", uri_set)
594-
test:is(tostring(error), expected_errmsg, "error message")
594+
test:is(error.message, expected_errmsg, "error message")
595595
expected_errmsg = "Incorrect type for URI parameters: should be a table"
596596
uri_set, error = uri.parse_many({"/tmp/unix.sock", params = ""})
597597
test:isnil(uri_set, "invalid uri", uri_set)
598-
test:is(tostring(error), expected_errmsg, "error message")
598+
test:is(error.message, expected_errmsg, "error message")
599599
expected_errmsg = "Default URI parameters are not allowed for single URI"
600600
uri_set, error = uri.parse_many({"/tmp/unix.sock", default_params = ""})
601601
test:isnil(uri_set, "invalid uri", uri_set)
602-
test:is(tostring(error), expected_errmsg, "error message")
602+
test:is(error.message, expected_errmsg, "error message")
603603
expected_errmsg = "Default URI parameters are not allowed for single URI"
604604
uri_set, error = uri.parse_many({"/tmp/unix.sock", default_params = ""})
605605
test:isnil(uri_set, "invalid uri", uri_set)
606-
test:is(tostring(error), expected_errmsg, "error message")
606+
test:is(error.message, expected_errmsg, "error message")
607607

608608
-- Mix "uri=" and numerical keys is banned
609609
expected_errmsg = "Invalid URI table: expected " ..
610610
"{uri = string, params = table}" .. " or " ..
611611
"{string, params = table}"
612612
uri_set, error = uri.parse_many({"/tmp/unix.sock", uri = "/tmp/unix.sock"})
613613
test:isnil(uri_set, "invalid uri", uri_set)
614-
test:is(tostring(error), expected_errmsg, "error message")
614+
test:is(error.message, expected_errmsg, "error message")
615615
-- Several URIs in one string is allowed only when the
616616
-- passed as a single string.
617617
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
618618
uri_set, error = uri.parse_many({"/tmp/unix.sock, /tmp/unix.sock"})
619619
test:isnil(uri_set, "invalid uri", uri_set)
620-
test:is(tostring(error), expected_errmsg, "error message")
620+
test:is(error.message, expected_errmsg, "error message")
621621
-- "params" table is allowed only for single URI
622622
expected_errmsg = "URI parameters are not allowed for multiple URIs"
623623
uri_set, error = uri.parse_many({
624624
"/tmp/unix.sock", "/tmp/unix.sock",
625625
params = {q1 = "v1"}
626626
})
627627
test:isnil(uri_set, "invalid uri", uri_set)
628-
test:is(tostring(error), expected_errmsg, "error message")
628+
test:is(error.message, expected_errmsg, "error message")
629629
-- "params" table is not allowed with nested tables
630630
expected_errmsg = "URI parameters are not allowed for multiple URIs"
631631
uri_set, error = uri.parse_many({
632632
{"/tmp/unix.sock"},
633633
params = {q1 = "v1"}
634634
})
635635
test:isnil(uri_set, "invalid uri", uri_set)
636-
test:is(tostring(error), expected_errmsg, "error message")
636+
test:is(error.message, expected_errmsg, "error message")
637637
-- "default_params" table is not allowed in nested URI tables
638638
expected_errmsg = "Default URI parameters are not allowed for single URI"
639639
uri_set, error = uri.parse_many({{"/tmp/unix.sock", default_params = {}}})
640640
test:isnil(uri_set, "invalid uri", uri_set)
641-
test:is(tostring(error), expected_errmsg, "error message")
641+
test:is(error.message, expected_errmsg, "error message")
642642
-- "default_params" table is not allowed for single URI
643643
expected_errmsg = "Default URI parameters are not allowed for single URI"
644644
uri_set, error = uri.parse_many({"/tmp/unix.sock", default_params = {}})
645645
test:isnil(uri_set, "invalid uri", uri_set)
646-
test:is(tostring(error), expected_errmsg, "error message")
646+
test:is(error.message, expected_errmsg, "error message")
647647
-- Only one URI is allowed in nested tables
648648
expected_errmsg = "Invalid URI table: expected " ..
649649
"{uri = string, params = table}" .. " or " ..
@@ -653,7 +653,7 @@ local function test_parse_invalid_uri_set_from_lua_table(test)
653653
default_params = {q = "v"}
654654
})
655655
test:isnil(uri_set, "invalid uri", uri_set)
656-
test:is(tostring(error), expected_errmsg, "error message")
656+
test:is(error.message, expected_errmsg, "error message")
657657
-- Nested URI tables is not allowed in nested tables
658658
expected_errmsg = "Invalid URI table: expected "..
659659
"{uri = string, params = table}" .. " or " ..
@@ -662,7 +662,7 @@ local function test_parse_invalid_uri_set_from_lua_table(test)
662662
{"/tmp/unix.sock", {}}
663663
})
664664
test:isnil(uri_set, "invalid uri", uri_set)
665-
test:is(tostring(error), expected_errmsg, "error message")
665+
test:is(error.message, expected_errmsg, "error message")
666666
-- Nested URI table without URI is now allowed
667667
expected_errmsg = "Invalid URI table: expected "..
668668
"{uri = string, params = table}" .. " or " ..
@@ -672,7 +672,7 @@ local function test_parse_invalid_uri_set_from_lua_table(test)
672672
{ params = {q = "v"} }
673673
})
674674
test:isnil(uri_set, "invalid uri", uri_set)
675-
test:is(tostring(error), expected_errmsg, "error message")
675+
test:is(error.message, expected_errmsg, "error message")
676676
-- Only string key types are allowed in "params" and
677677
-- "default_params" table
678678
expected_errmsg = "Incorrect type for URI parameter name: " ..
@@ -682,14 +682,14 @@ local function test_parse_invalid_uri_set_from_lua_table(test)
682682
params = {"v"},
683683
})
684684
test:isnil(uri_set, "invalid uri", uri_set)
685-
test:is(tostring(error), expected_errmsg, "error message")
685+
test:is(error.message, expected_errmsg, "error message")
686686
expected_errmsg = "Default URI parameters are not allowed for single URI"
687687
uri_set, error = uri.parse_many({
688688
"/tmp/unix.sock",
689689
default_params = {"v"},
690690
})
691691
test:isnil(uri_set, "invalid uri", uri_set)
692-
test:is(tostring(error), expected_errmsg, "error message")
692+
test:is(error.message, expected_errmsg, "error message")
693693
-- Invalid type of values in "params" and
694694
-- "default_params" table
695695
expected_errmsg = "Incorrect type for URI parameter value: " ..
@@ -699,53 +699,53 @@ local function test_parse_invalid_uri_set_from_lua_table(test)
699699
params = {q = function() end},
700700
})
701701
test:isnil(uri_set, "invalid uri", uri_set)
702-
test:is(tostring(error), expected_errmsg, "error message")
702+
test:is(error.message, expected_errmsg, "error message")
703703
expected_errmsg = "Default URI parameters are not allowed for single URI"
704704
uri_set, error = uri.parse_many({
705705
"/tmp/unix.sock",
706706
default_params = {q = function() end},
707707
})
708708
test:isnil(uri_set, "invalid uri", uri_set)
709-
test:is(tostring(error), expected_errmsg, "error message")
709+
test:is(error.message, expected_errmsg, "error message")
710710
expected_errmsg = "Incorrect type for URI parameter value: "..
711711
"should be string or number"
712712
uri_set, error = uri.parse_many({
713713
"/tmp/unix.sock",
714714
params = {q = {function() end}},
715715
})
716716
test:isnil(uri_set, "invalid uri", uri_set)
717-
test:is(tostring(error), expected_errmsg, "error message")
717+
test:is(error.message, expected_errmsg, "error message")
718718
expected_errmsg = "Default URI parameters are not allowed for single URI"
719719
uri_set, error = uri.parse_many({
720720
"/tmp/unix.sock",
721721
default_params = {q = {function() end}},
722722
})
723723
test:isnil(uri_set, "invalid uri", uri_set)
724-
test:is(tostring(error), expected_errmsg, "error message")
724+
test:is(error.message, expected_errmsg, "error message")
725725
-- Invalid uri string in URIs table
726726
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
727727
uri_set, error = uri.parse_many({
728728
"/tmp/unix.sock",
729729
"://"
730730
})
731731
test:isnil(uri_set, "invalid uri", uri_set)
732-
test:is(tostring(error), expected_errmsg, "error message")
732+
test:is(error.message, expected_errmsg, "error message")
733733
-- Invalid uri in nested URI table
734734
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
735735
uri_set, error = uri.parse_many({
736736
"/tmp/unix.sock",
737737
{"://"}
738738
})
739739
test:isnil(uri_set, "invalid uri", uri_set)
740-
test:is(tostring(error), expected_errmsg, "error message")
740+
test:is(error.message, expected_errmsg, "error message")
741741
-- Same as previous but with "uri=" syntax
742742
expected_errmsg = "Incorrect URI: expected host:service or /unix.socket"
743743
uri_set, error = uri.parse_many({
744744
"/tmp/unix.sock",
745745
{uri = "://"}
746746
})
747747
test:isnil(uri_set, "invalid uri", uri_set)
748-
test:is(tostring(error), expected_errmsg, "error message")
748+
test:is(error.message, expected_errmsg, "error message")
749749
end
750750

751751
local test = tap.test("uri")

test/box-luatest/gh_6085_limit_iteration_in_space_test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ g.test_limit_iteration = function()
3333
local fib = fiber.new(fiber_f)
3434
fib:set_joinable(true)
3535
local _, err = fib:join()
36-
t.assert_equals(tostring(err), "fiber slice is exceeded")
36+
t.assert_equals(err.message, "fiber slice is exceeded")
3737
end
3838

3939
fiber.set_max_slice(0.2)
@@ -92,7 +92,7 @@ g.test_limit_on_sigurg = function()
9292
os.execute('kill -URG ' .. tonumber(pid))
9393
local _, err = future:wait_result(1.5)
9494
local end_time = clock.monotonic()
95-
t.assert_equals(tostring(err), "fiber slice is exceeded")
95+
t.assert_equals(err.message, "fiber slice is exceeded")
9696
-- Must end before slice is over.
9797
t.assert(end_time - start_time < 3)
9898
end

test/box-luatest/gh_7939_fix_meamleak_on_tuple_encode_test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ g.test_misc_region_leaks = function(cg)
176176
}
177177
');]])
178178
t.assert_equals(ret, nil)
179-
t.assert_equals(tostring(err), errmsg)
179+
t.assert_equals(err.message, errmsg)
180180
t.assert_equals(before, mem_used())
181181

182182
ret, err = box.execute('SELECT ?;', {{trouble}})
183183
t.assert_equals(ret, nil)
184-
t.assert_equals(tostring(err), errmsg)
184+
t.assert_equals(err.message, errmsg)
185185
t.assert_equals(before, mem_used())
186186
end)
187187
end

test/box-luatest/gh_8802_box_session_push_deprecation_test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ g.test = function(cg)
6565
t.assert_equals(ok, compat.box_session_push_deprecation:is_old(),
6666
'box.session.push status')
6767
if not ok then
68-
t.assert_equals(tostring(err), 'box.session.push is deprecated',
68+
t.assert_equals(err.message, 'box.session.push is deprecated',
6969
'box.session.push error')
7070
end
7171
end)
@@ -84,7 +84,7 @@ g.test = function(cg)
8484
t.assert_equals(ok, compat.box_session_push_deprecation:is_old(),
8585
'box.session.push status')
8686
if not ok then
87-
t.assert_equals(tostring(err), 'box.session.push is deprecated',
87+
t.assert_equals(err.message, 'box.session.push is deprecated',
8888
'box.session.push error')
8989
end
9090
end)

0 commit comments

Comments
 (0)