diff --git a/src/lua/print.lua b/src/lua/print.lua index 75fe436b731dc0cf6bdb2125db6cb6e8dc250ea4..c9213e200a4f6d3ac74cd3f9a873387e3e7a6fcc 100644 --- a/src/lua/print.lua +++ b/src/lua/print.lua @@ -8,10 +8,13 @@ _G.print = function(...) if M.before_cb ~= nil then M.before_cb() end - M.raw_print(...) + local ok, err = pcall(M.raw_print, ...) if M.after_cb ~= nil then M.after_cb() end + if not ok then + error(err) + end end return M diff --git a/test/app-luatest/gh_8136_fix_print_wrapper_not_handling_errors_thrown_from_print_test.lua b/test/app-luatest/gh_8136_fix_print_wrapper_not_handling_errors_thrown_from_print_test.lua new file mode 100644 index 0000000000000000000000000000000000000000..6bfa3b2ad2801f29409f3dd6ded5e8c0d880c7f6 --- /dev/null +++ b/test/app-luatest/gh_8136_fix_print_wrapper_not_handling_errors_thrown_from_print_test.lua @@ -0,0 +1,32 @@ +local it = require('test.interactive_tarantool') + +local t = require('luatest') +local g = t.group() + +-- Checks that `print` throwing an error is handled correctly. +g.test_basic_print_with_exception = function() + local child = it.new({args = {'-l', 'fiber'}}) + + child:execute_command([[ + _ = fiber.create(function() + fiber.name('print_flood', {truncate = true}) + while true do + pcall(function() + print(setmetatable({}, {__tostring = error})) + end) + print('flood') + fiber.sleep(0.01) + end + end) + ]]) + child:assert_empty_response() + + local exp_line = it.PROMPT .. it.CR .. it.ERASE_IN_LINE .. + it.PROMPT .. it.CR .. it.ERASE_IN_LINE .. + 'flood' + for _ = 1, 10 do + child:assert_line(exp_line) + end + + child:close() +end