forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lua: fix
print
wrapper to handle errors thrown from print
Both of the callbacks in the `print` wrapper are expected to be called, but `print` may throw errors, e.g., `print(setmetatable({}, {__tostring = error})`, so we need to call it in a protected environment and execute the 'after' callback even if `print` throws. Closes tarantool#8136 NO_DOC=bugfix
- Loading branch information
1 parent
182034d
commit 9ac24e1
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...s/unreleased/gh-8136-fix-print-wrapper-not-handling-errors-thrown-from-print.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## bugfix/lua | ||
|
||
* Fixed `print` function wrapper not handling errors thrown from `print`: this | ||
could render the hide/show prompt feature (gh-7169) to be useless and leak | ||
memory (gh-8136). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/box-luatest/gh_8136_fix_print_wrapper_not_handling_errors_thrown_from_print_test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |