From e17515d31c00523cbfacca1121cea8691ef8e303 Mon Sep 17 00:00:00 2001 From: Ilya Verbin <iverbin@tarantool.org> Date: Fri, 8 Jul 2022 21:30:22 +0300 Subject: [PATCH] console: handle internal.format_lua exceptions Currently the call to internal.format_lua in format_lua_value is covered by pcall only for `status == true`, however the opposite case also can raise an exception. This patch adds the missed exception handling. Part of #6781 Part of #6934 NO_DOC=bugfix NO_CHANGELOG=minor bug NO_TEST=not possible to trigger format_lua failure for !status --- src/box/lua/console.lua | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 5aeaad41d4..9d44778bc6 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -74,22 +74,20 @@ end -- -- Format a Lua value. local function format_lua_value(status, internal_opts, value) - local err - if status then - status, err = pcall(internal.format_lua, internal_opts, value) - if status then - return err - else - local m = 'console: exception while formatting output: "%s"' - err = m:format(tostring(err)) + if not status then + if value == nil then + value = box.NULL end + value = { error = value } + end + local ok, res = pcall(internal.format_lua, internal_opts, value) + if ok then + return res else - err = value - if err == nil then - err = box.NULL - end + local m = 'console: exception while formatting the output: "%s"' + local err = m:format(tostring(res)) + return internal.format_lua(internal_opts, { error = err }) end - return internal.format_lua(internal_opts, { error = err }) end -- -- GitLab