Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Leonid Vasiliev <lvasiliev@tarantool.org>,
	alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH V5 2/6] error: send custom type in IProto
Date: Sat, 18 Apr 2020 22:39:49 +0200	[thread overview]
Message-ID: <3b5898e4-c2bc-2704-ce63-e492799e4231@tarantool.org> (raw)
In-Reply-To: <4b3ee41137cefd5d01a34763d33be897ec5f8c09.1587223627.git.lvasiliev@tarantool.org>

On 18/04/2020 17:29, Leonid Vasiliev wrote:
> Error custom type feature was added to the public Lua API in the
> previous commit. 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 attribute 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, has MP_STR type, and speaks for itself.
> 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>)`.

I added a note, that the field is optional:

    The field is optional, and may be not present in response, if the
    error does not have a custom type.

Talking of the patch - I still think IProto errors should reuse the
code used to encode/decode MP_EXT errors. If we go for that, this patch
is going to be 100% overrode by that refactoring, and does not make
sense as a separate commit.

There appeared a problem, that it is not that simple, since netbox
is not able to decode MP_EXT for now, as Leonid noticed. So there is
a workaround.

We discussed it verbally, below is the solution.

Now we have `IPROTO_ERROR_STACK` of a format:
```
IPROTO_ERROR_STACK <MP_ARRAY>: [
    <MP_MAP> {
        IPROTO_ERROR_CODE: <MP_UINT>,
        IPROTO_ERROR_MESSAGE: <MP_STR>,
    },
    ...
]
```
MP_ERROR format is going to be this:
```
    <MP_EXT>:
        MP_ERROR <MP_MAP>: {
            MP_ERROR_STACK <MP_ARRAY>: [
                <MP_MAP> {
                    MP_ERROR_TYPE: <MP_STR>,
                    MP_ERROR_FILE: <MP_STR>,
                    MP_ERROR_LINE: <MP_UINT>,
                    MP_ERROR_REASON: <MP_STR>,
                    MP_ERROR_ERRNO: <MP_UINT>,
                    MP_ERROR_FIELDS: <MP_MAP> {
                        <MP_STR>: ...,
                        <MP_STR>: ...,
                        ...
                    },
                },
                ...
            }
        }
```

I propose to make these formats the same, not counting `MP_EXT`.
For that we rename the old `IPROTO_ERROR` to `IPROTO_ERROR_24`
(similar to `IPROTO_CALL_16`), `IPROTO_ERROR_STACK` rename to
`IPROTO_ERROR`. Renames are ok, since the underlying numbers
are not going to change. So IProto error will look like this:
```
IPROTO_ERROR <MP_MAP>: {
    IPROTO_ERROR_STACK <MP_ARRAY>: [
        <MP_MAP> {
            IPROTO_ERROR_TYPE: <MP_STR>,
            IPROTO_ERROR_FILE: <MP_STR>,
            IPROTO_ERROR_LINE: <MP_UINT>,
            IPROTO_ERROR_REASON: <MP_STR>,
            IPROTO_ERROR_ERRNO: <MP_UINT>,
            IPROTO_ERROR_FIELDS: <MP_MAP> {
                <MP_STR>: ...,
                <MP_STR>: ...,
                ...
            },
        },
        ...
    }
}
```
+ `IPROTO_ERROR_24`, like it is done in the stacked diag now.
Essentially, it looks exactly the same as `MP_ERROR` - `MP_EXT`
header.

Then we do that all keys `IPROTO_ERROR_*` and `MP_ERROR_*` have
the same values. So any `IPROTO_ERROR_<name>` == `MP_ERROR_<name>`.
For example, `MP_ERROR_STACK = 0x00`, and `IPROTO_ERROR_STACK = 0x00`.
 
Now all packing/unpacking can be done by the same functions for
IProto and for normal returns. IProto will encode it as `MP_MAP` in
its header, normal serialization will be via `MP_EXT`.

  reply	other threads:[~2020-04-18 20:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-18 15:29 [Tarantool-patches] [PATCH V5 0/6] Extending error functionality Leonid Vasiliev
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 1/6] error: add custom error type Leonid Vasiliev
2020-04-18 18:52   ` Vladislav Shpilevoy
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 2/6] error: send custom type in IProto Leonid Vasiliev
2020-04-18 20:39   ` Vladislav Shpilevoy [this message]
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 3/6] session: add offset to SQL session settings array Leonid Vasiliev
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 4/6] error: add session setting for error type marshaling Leonid Vasiliev
2020-04-18 20:40   ` Vladislav Shpilevoy
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 5/6] error: update constructors of some errors Leonid Vasiliev
2020-04-18 20:39   ` Vladislav Shpilevoy
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 6/6] error: add error MsgPack encoding Leonid Vasiliev
2020-04-18 20:39   ` Vladislav Shpilevoy
2020-04-18 21:14 ` [Tarantool-patches] [PATCH V5 5.5/6] box: move Lua MP_EXT decoder from tuple.c 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=3b5898e4-c2bc-2704-ce63-e492799e4231@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=lvasiliev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH V5 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