From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5542C4696C6 for ; Wed, 15 Apr 2020 12:32:06 +0300 (MSK) From: Leonid Vasiliev Date: Wed, 15 Apr 2020 12:31:58 +0300 Message-Id: <6796eb0c695f8cfb499dd29cb74f899fb896bbad.1586934134.git.lvasiliev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Subject: [Tarantool-patches] [PATCH V3 3/7] error: send custom type in IProto List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Error custom type features were added to the public Lua API in the previous commits. This one makes the new attribute being sent in IProto. Co-authored-by: Vladislav Shpilevoy Needed for #4398 @TarantoolBot document Title: New error object attributes in IProto Error objects in IProto already have 2 fields: `IPROTO_ERROR_CODE = 0x01` and `IPROTO_ERROR_MESSAGE = 0x02`. Now added: `IPROTO_ERROR_CUSTOM_TYPE = 0x03`. It's optional, have MP_STR type, and speak for themselves. Custom error type is error object attribute. This is what a user specifies in `box.error.new({type = })` or `box.error.new()`. --- extra/exports | 1 + src/box/iproto_constants.h | 1 + src/box/lua/net_box.lua | 14 +++++++++++--- src/box/xrow.c | 9 ++++++++- test/box/error.result | 40 ++++++++++++++++++++++++++++++++++++++++ test/box/error.test.lua | 17 +++++++++++++++++ 6 files changed, 78 insertions(+), 4 deletions(-) diff --git a/extra/exports b/extra/exports index 9467398..b01b437 100644 --- a/extra/exports +++ b/extra/exports @@ -242,6 +242,7 @@ box_error_last box_error_clear box_error_set error_set_prev +error_set_traceback box_latch_new box_latch_delete box_latch_lock diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index 7ed8296..1fca97b 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -154,6 +154,7 @@ enum iproto_ballot_key { enum iproto_error_key { IPROTO_ERROR_CODE = 0x01, IPROTO_ERROR_MESSAGE = 0x02, + IPROTO_ERROR_CUSTOM_TYPE = 0x03, }; #define bit(c) (1ULL<cause) { - mpstream_encode_map(stream, 2); + uint32_t map_size = 2; + const char *custom_type = box_error_custom_type(it); + map_size += (custom_type != NULL); + 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 (custom_type != NULL) { + mpstream_encode_uint(stream, IPROTO_ERROR_CUSTOM_TYPE); + mpstream_encode_str(stream, custom_type); + } } } diff --git a/test/box/error.result b/test/box/error.result index b717a4f..ced227f 100644 --- a/test/box/error.result +++ b/test/box/error.result @@ -949,3 +949,43 @@ e = box.error.new({type = string.rep('a', 128)}) | --- | - 63 | ... + +-- +-- Check how custom error type are passed through +-- IProto. +-- +netbox = require('net.box') + | --- + | ... +box.schema.user.grant('guest', 'super') + | --- + | ... +c = netbox.connect(box.cfg.listen) + | --- + | ... +_, e = pcall(c.call, c, 'box.error', { \ + {code = 123, type = 'TestType', reason = 'Test reason'} \ +}) + | --- + | ... +e = e:unpack() + | --- + | ... +e.trace = nil + | --- + | ... +e + | --- + | - code: 123 + | type: TestType + | custom_type: TestType + | message: Test reason + | base_type: CustomError + | ... + +c:close() + | --- + | ... +box.schema.user.revoke('guest', 'super') + | --- + | ... diff --git a/test/box/error.test.lua b/test/box/error.test.lua index fe40518..b71ab52 100644 --- a/test/box/error.test.lua +++ b/test/box/error.test.lua @@ -278,3 +278,20 @@ e:unpack() -- Try too long type name. e = box.error.new({type = string.rep('a', 128)}) #e.type + +-- +-- Check how custom error type are passed through +-- IProto. +-- +netbox = require('net.box') +box.schema.user.grant('guest', 'super') +c = netbox.connect(box.cfg.listen) +_, e = pcall(c.call, c, 'box.error', { \ + {code = 123, type = 'TestType', reason = 'Test reason'} \ +}) +e = e:unpack() +e.trace = nil +e + +c:close() +box.schema.user.revoke('guest', 'super') -- 2.7.4