error: add error MsgPack encoding
Co-authored-by:
Vladislav <Shpilevoy<v.shpilevoy@tarantool.org>
Closes #4398
@TarantoolBot document
Title: Error objects encoding in MessagePack
Until now an error sent over IProto, or serialized into
MessagePack was turned into a string consisting of the error
message. As a result, all other error object attributes were lost,
including type of the object. On client side seeing a string it
was not possible to tell whether the string is a real string, or
it is a serialized error.
To deal with that the error objects encoding is reworked from the
scratch. Now, when session setting `error_marshaling_enabled` is
true, all fibers of that session will encode error objects as a
new MP_EXT type - MP_ERROR (0x03).
```
+--------+----------+========+
| MP_EXT | MP_ERROR | MP_MAP |
+--------+----------+========+
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_MESSAGE: <MP_STR>,
MP_ERROR_ERRNO: <MP_UINT>,
MP_ERROR_CODE: <MP_UINT>,
MP_ERROR_FIELDS: <MP_MAP> {
<MP_STR>: ...,
<MP_STR>: ...,
...
},
...
},
...
]
}
```
On the top level there is a single key: `MP_ERROR_STACK = 0x00`.
More keys can be added in future, and a client should ignore all
unknown keys to keep compatibility with new versions.
Every error in the stack is a map with the following keys:
* `MP_ERROR_TYPE = 0x00` - error type. This is what is visible in
`<error_object>.base_type` field;
* `MP_ERROR_FILE = 0x01` - file name from `<error_object>.trace`;
* `MP_ERROR_LINE = 0x02` - line from `<error_object>.trace`;
* `MP_ERROR_MESSAGE = 0x03` - error message from
`<error_object>.message`;
* `MP_ERROR_ERRNO = 0x04` - errno saved at the moment of the error
creation. Visible in `<error_object>.errno`;
* `MP_ERROR_CODE = 0x05` - error code. Visible in
`<error_object>.code` and in C function `box_error_code()`.
* `MP_ERROR_FIELDS = 0x06` - additional fields depending on error
type. For example, AccessDenied error type stores here fields
`access_type`, `object_type`, `object_name`. Connector's code
should ignore unknown keys met here, and be ready, that for some
existing errors new fields can be added, old can be dropped.
Showing
- src/box/CMakeLists.txt 3 additions, 3 deletionssrc/box/CMakeLists.txt
- src/box/lua/init.c 36 additions, 0 deletionssrc/box/lua/init.c
- src/box/mp_error.cc 533 additions, 0 deletionssrc/box/mp_error.cc
- src/box/mp_error.h 60 additions, 0 deletionssrc/box/mp_error.h
- src/lib/core/mp_extension_types.h 1 addition, 0 deletionssrc/lib/core/mp_extension_types.h
- src/lua/error.c 1 addition, 1 deletionsrc/lua/error.c
- src/lua/error.h 1 addition, 0 deletionssrc/lua/error.h
- src/lua/msgpack.c 2 additions, 0 deletionssrc/lua/msgpack.c
- src/lua/utils.c 6 additions, 2 deletionssrc/lua/utils.c
- test/box-tap/extended_error.test.lua 124 additions, 0 deletionstest/box-tap/extended_error.test.lua
- test/unit/CMakeLists.txt 2 additions, 0 deletionstest/unit/CMakeLists.txt
- test/unit/mp_error.cc 473 additions, 0 deletionstest/unit/mp_error.cc
- test/unit/mp_error.result 44 additions, 0 deletionstest/unit/mp_error.result
Loading
Please register or sign in to comment