From: Leonid Vasiliev <lvasiliev@tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH V4 2/6] error: send custom type in IProto
Date: Thu, 16 Apr 2020 20:38:41 +0300 [thread overview]
Message-ID: <4d28379a84646a41f9a02677a176fd1ee037a0b8.1587058424.git.lvasiliev@tarantool.org> (raw)
In-Reply-To: <cover.1587058424.git.lvasiliev@tarantool.org>
In-Reply-To: <cover.1587058424.git.lvasiliev@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<v.shpilevoy@tarantool.org>
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 = <custom_type>})` or
`box.error.new(<custom_type>)`.
---
| 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(-)
--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<<IPROTO_##c)
diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
index 07fa54c..95f9cf8 100644
--- a/src/box/lua/net_box.lua
+++ b/src/box/lua/net_box.lua
@@ -10,6 +10,11 @@ local urilib = require('uri')
local internal = require('net.box.lib')
local trigger = require('internal.trigger')
+ffi.cdef[[
+void
+error_set_traceback(struct error *e, const char *traceback);
+]]
+
local band = bit.band
local max = math.max
local fiber_clock = fiber.clock
@@ -47,6 +52,7 @@ local IPROTO_ERROR_KEY = 0x31
local IPROTO_ERROR_STACK = 0x52
local IPROTO_ERROR_CODE = 0x01
local IPROTO_ERROR_MESSAGE = 0x02
+local IPROTO_ERROR_CUSTOM_TYPE = 0x03
local IPROTO_GREETING_SIZE = 128
local IPROTO_CHUNK_KEY = 128
local IPROTO_OK_KEY = 0
@@ -285,9 +291,11 @@ local function create_transport(host, port, user, password, callback,
local prev = nil
for i = #self.response, 1, -1 do
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 new_err = box.error.new({
+ type = error[IPROTO_ERROR_CUSTOM_TYPE],
+ code = error[IPROTO_ERROR_CODE],
+ reason = error[IPROTO_ERROR_MESSAGE],
+ })
new_err:set_prev(prev)
prev = new_err
end
diff --git a/src/box/xrow.c b/src/box/xrow.c
index 5494b41..a717da6 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -494,11 +494,18 @@ 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);
+ 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 82db453..d231f5d 100644
--- a/test/box/error.result
+++ b/test/box/error.result
@@ -889,3 +889,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: 214
+ | base_type: CustomError
+ | type: TestType
+ | custom_type: TestType
+ | message: Test reason
+ | ...
+
+c:close()
+ | ---
+ | ...
+box.schema.user.revoke('guest', 'super')
+ | ---
+ | ...
diff --git a/test/box/error.test.lua b/test/box/error.test.lua
index 38f7406..3258024 100644
--- a/test/box/error.test.lua
+++ b/test/box/error.test.lua
@@ -244,3 +244,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
next prev parent reply other threads:[~2020-04-16 17:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-16 17:38 [Tarantool-patches] [PATCH V4 0/6] Extending error functionality Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 1/6] error: add custom error type Leonid Vasiliev
2020-04-17 0:49 ` Vladislav Shpilevoy
2020-04-18 17:14 ` lvasiliev
2020-04-16 17:38 ` Leonid Vasiliev [this message]
2020-04-17 0:51 ` [Tarantool-patches] [PATCH V4 2/6] error: send custom type in IProto Vladislav Shpilevoy
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 3/6] session: add offset to SQL session settings array Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 4/6] error: add session setting for error type marshaling Leonid Vasiliev
2020-04-16 19:48 ` Konstantin Osipov
2020-04-17 0:51 ` Vladislav Shpilevoy
2020-04-17 7:35 ` Konstantin Osipov
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 5/6] error: update constructors of some errors Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 6/6] error: add error MsgPack encoding Leonid Vasiliev
2020-04-17 0:58 ` Vladislav Shpilevoy
2020-04-18 17:46 ` lvasiliev
2020-04-17 0:51 ` [Tarantool-patches] [PATCH V4 0/6] Extending error functionality Vladislav Shpilevoy
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=4d28379a84646a41f9a02677a176fd1ee037a0b8.1587058424.git.lvasiliev@tarantool.org \
--to=lvasiliev@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH V4 2/6] error: send custom type in 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