From: Leonid Vasiliev <lvasiliev@tarantool.org> To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v2 3/5] error: Increase the number of fields transmitted through IPROTO Date: Fri, 10 Apr 2020 11:10:41 +0300 [thread overview] Message-ID: <36240df4750932601c23b3b3fe4fe11e1034dfb1.1586505741.git.lvasiliev@tarantool.org> (raw) In-Reply-To: <cover.1586505741.git.lvasiliev@tarantool.org> In-Reply-To: <cover.1586505741.git.lvasiliev@tarantool.org> Has been added IPROTO_ERROR_TRACEBACK and IPROTO_ERROR_CUSTOM_TYPE fields to IPROTO_ERROR_STACK for transfering through network a backtrace and custom type. Needed for #4398 --- src/box/iproto_constants.h | 2 ++ src/box/lua/error.cc | 23 +++++++++++++++++++++++ src/box/lua/net_box.lua | 21 ++++++++++++++++++++- src/box/xrow.c | 19 ++++++++++++++++++- 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index 7ed8296..7daa980 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -154,6 +154,8 @@ enum iproto_ballot_key { enum iproto_error_key { IPROTO_ERROR_CODE = 0x01, IPROTO_ERROR_MESSAGE = 0x02, + IPROTO_ERROR_TRACEBACK = 0x03, + IPROTO_ERROR_CUSTOM_TYPE = 0x04, }; #define bit(c) (1ULL<<IPROTO_##c) diff --git a/src/box/lua/error.cc b/src/box/lua/error.cc index 1bcce1f..27dee7a 100644 --- a/src/box/lua/error.cc +++ b/src/box/lua/error.cc @@ -236,6 +236,25 @@ luaT_error_custom_type(lua_State *L) } static int +luaT_error_set_lua_traceback(lua_State *L) +{ + if (lua_gettop(L) < 2) + return luaL_error(L, "Usage: box.error.set_lua_traceback"\ + "(error, traceback)"); + + struct error *e = luaL_checkerror(L, 1); + + if (lua_type(L, 2) == LUA_TSTRING) { + error_set_lua_traceback(e, lua_tostring(L, 2)); + } else { + return luaL_error(L, "Usage: box.error.set_lua_traceback"\ + "(error, traceback)"); + } + + return 0; +} + +static int luaT_error_clear(lua_State *L) { if (lua_gettop(L) >= 1) @@ -395,6 +414,10 @@ box_lua_error_init(struct lua_State *L) { lua_pushcfunction(L, luaT_error_custom_type); lua_setfield(L, -2, "custom_type"); } + { + lua_pushcfunction(L, luaT_error_set_lua_traceback); + lua_setfield(L, -2, "set_lua_traceback"); + } lua_setfield(L, -2, "__index"); } lua_setmetatable(L, -2); diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 07fa54c..1e0cd7a 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -47,6 +47,8 @@ local IPROTO_ERROR_KEY = 0x31 local IPROTO_ERROR_STACK = 0x52 local IPROTO_ERROR_CODE = 0x01 local IPROTO_ERROR_MESSAGE = 0x02 +local IPROTO_ERROR_TRACEBACK = 0x03 +local IPROTO_ERROR_CUSTOM_TYPE = 0x04 local IPROTO_GREETING_SIZE = 128 local IPROTO_CHUNK_KEY = 128 local IPROTO_OK_KEY = 0 @@ -287,7 +289,24 @@ local function create_transport(host, port, user, password, callback, local error = self.response[i] local code = error[IPROTO_ERROR_CODE] local msg = error[IPROTO_ERROR_MESSAGE] - local new_err = box.error.new({code = code, reason = msg}) + local custom_type = error[IPROTO_ERROR_CUSTOM_TYPE] + local traceback = error[IPROTO_ERROR_TRACEBACK] + + local new_err + if custom_type then + new_err = box.error.new({type = custom_type, + reason = msg, + traceback = false}) + else + new_err = box.error.new({code = code, + reason = msg, + traceback = false}) + end + + if traceback then + box.error.set_lua_traceback(new_err, traceback) + end + new_err:set_prev(prev) prev = new_err end diff --git a/src/box/xrow.c b/src/box/xrow.c index be026a4..cd88e49 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -494,11 +494,28 @@ mpstream_iproto_encode_error(struct mpstream *stream, const struct error *error) mpstream_encode_uint(stream, IPROTO_ERROR_STACK); mpstream_encode_array(stream, err_cnt); for (const struct error *it = error; it != NULL; it = it->cause) { - mpstream_encode_map(stream, 2); + /* Code and message are necessary fields */ + uint32_t map_size = 2; + const char *custom_type = NULL; + if (it->lua_traceback) + ++map_size; + if (strcmp(box_error_type(it), "CustomError") == 0) { + ++map_size; + custom_type = box_custom_error_type(it); + } + mpstream_encode_map(stream, map_size); mpstream_encode_uint(stream, IPROTO_ERROR_CODE); mpstream_encode_uint(stream, box_error_code(it)); mpstream_encode_uint(stream, IPROTO_ERROR_MESSAGE); mpstream_encode_str(stream, it->errmsg); + if (it->lua_traceback) { + mpstream_encode_uint(stream, IPROTO_ERROR_TRACEBACK); + mpstream_encode_str(stream, it->lua_traceback); + } + if (custom_type) { + mpstream_encode_uint(stream, IPROTO_ERROR_CUSTOM_TYPE); + mpstream_encode_str(stream, custom_type); + } } } -- 2.7.4
next prev parent reply other threads:[~2020-04-10 8:10 UTC|newest] Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-10 8:10 [Tarantool-patches] [PATCH v2 0/5] Extending error functionality Leonid Vasiliev 2020-04-10 8:10 ` [Tarantool-patches] [PATCH v2 1/5] error: Add a Lua backtrace to error Leonid Vasiliev 2020-04-14 1:11 ` Vladislav Shpilevoy 2020-04-15 9:25 ` lvasiliev 2020-04-16 0:00 ` Vladislav Shpilevoy 2020-04-16 1:11 ` Alexander Turenko 2020-04-16 8:58 ` lvasiliev 2020-04-16 9:30 ` Alexander Turenko 2020-04-16 12:27 ` lvasiliev 2020-04-16 12:45 ` Alexander Turenko 2020-04-16 17:48 ` lvasiliev 2020-04-16 8:40 ` lvasiliev 2020-04-16 9:04 ` lvasiliev 2020-04-10 8:10 ` [Tarantool-patches] [PATCH v2 2/5] error: Add the custom error type Leonid Vasiliev 2020-04-14 1:11 ` Vladislav Shpilevoy 2020-04-15 9:25 ` lvasiliev 2020-04-16 0:02 ` Vladislav Shpilevoy 2020-04-16 9:18 ` lvasiliev 2020-04-16 21:03 ` Vladislav Shpilevoy 2020-04-10 8:10 ` Leonid Vasiliev [this message] 2020-04-14 1:12 ` [Tarantool-patches] [PATCH v2 3/5] error: Increase the number of fields transmitted through IPROTO Vladislav Shpilevoy 2020-04-15 9:25 ` lvasiliev 2020-04-16 0:02 ` Vladislav Shpilevoy 2020-04-10 8:10 ` [Tarantool-patches] [PATCH v2 4/5] iproto: Add session settings for IPROTO Leonid Vasiliev 2020-04-14 1:12 ` Vladislav Shpilevoy 2020-04-15 9:26 ` lvasiliev 2020-04-16 0:06 ` Vladislav Shpilevoy 2020-04-16 9:36 ` lvasiliev 2020-04-16 21:04 ` Vladislav Shpilevoy 2020-04-10 8:10 ` [Tarantool-patches] [PATCH v2 5/5] iproto: Update error MsgPack encoding Leonid Vasiliev 2020-04-14 1:12 ` Vladislav Shpilevoy 2020-04-15 9:25 ` lvasiliev 2020-04-16 0:11 ` Vladislav Shpilevoy 2020-04-16 10:04 ` lvasiliev 2020-04-16 21:06 ` Vladislav Shpilevoy 2020-04-14 1:10 ` [Tarantool-patches] [PATCH v2 0/5] Extending error functionality Vladislav Shpilevoy 2020-04-15 9:48 ` lvasiliev
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=36240df4750932601c23b3b3fe4fe11e1034dfb1.1586505741.git.lvasiliev@tarantool.org \ --to=lvasiliev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 3/5] error: Increase the number of fields transmitted through IPROTO' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox