-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msgpack: support error extension type
Tarantool supports error extension type since version 2.4.1 [1], encoding was introduced in Tarantool 2.10.0 [2]. This patch introduces the support of Tarantool error extension type in msgpack decoders and encoders. Tarantool error extension type objects are decoded to `tarantool.BoxError` type. `tarantool.BoxError` may be encoded to Tarantool error extension type objects. Error extension type internals are the same as errors extra information: the only difference is that extra information is encoded as a separate error dictionary field and error extension type objects is encoded as MessagePack extension type objects. Error extension type objects are parsed based on common encoder/decoder rules. String fields are converted to either `str` or `bytes` based on `encoding` mode. The only way to receive an error extension type object from Tarantool is to receive an explicitly built `box.error` object: either from `return box.error.new(...)` or a tuple with it. All errors raised within Tarantool (including those raised with `box.error(...)`) are encoded based on the same rules as simple errors due to backward compatibility. It is possible to create error extension type objects with Python code, but it not likely to be really useful since most of their fields is computed on error initialization on the server side (even for custom error types): ``` tarantool.BoxError( type='ClientError', file='[string " local err = box.error.ne..."]', line=1, message='Unknown error', errno=0, errcode=0, ) ``` 1. tarantool/tarantool#4398 2. tarantool/tarantool#6433 Closes #232
- Loading branch information
1 parent
88e9299
commit ee004a0
Showing
18 changed files
with
654 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Tarantool `error`_ extension type support module. | ||
Refer to :mod:`~tarantool.msgpack_ext.types.error`. | ||
.. _error: https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-error-type | ||
""" | ||
|
||
from tarantool.types import ( | ||
encode_box_error, | ||
decode_box_error, | ||
) | ||
|
||
EXT_ID = 3 | ||
""" | ||
`error`_ type id. | ||
""" | ||
|
||
def encode(obj, packer): | ||
""" | ||
Encode an error object. | ||
:param obj: Error to encode. | ||
:type obj: :class:`tarantool.BoxError` | ||
:param packer: msgpack packer to encode error dictionary. | ||
:type packer: :class:`msgpack.Packer` | ||
:return: Encoded error. | ||
:rtype: :obj:`bytes` | ||
""" | ||
|
||
err_map = encode_box_error(obj) | ||
return packer.pack(err_map) | ||
|
||
def decode(data, unpacker): | ||
""" | ||
Decode an error object. | ||
:param obj: Error to decode. | ||
:type obj: :obj:`bytes` | ||
:param unpacker: msgpack unpacker to decode error dictionary. | ||
:type unpacker: :class:`msgpack.Unpacker` | ||
:return: Decoded error. | ||
:rtype: :class:`tarantool.BoxError` | ||
""" | ||
|
||
unpacker.feed(data) | ||
err_map = unpacker.unpack() | ||
return decode_box_error(err_map) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.