-
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.
iproto: support errors extra information
Since Tarantool 2.4.1, iproto error responses contain extra info with backtrace. After this patch, DatabaseError would contain `extra_info` property, if it was provided. Error extra information is parsed based on common encoder/decoder rules. String fields are converted to either `str` or `bytes` based on `encoding` mode. 1. https://www.tarantool.io/en/doc/latest/dev_guide/internals/box_protocol/#responses-for-errors Part of #232
- Loading branch information
1 parent
8118e7d
commit 88e9299
Showing
11 changed files
with
250 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module :py:mod:`tarantool.types` | ||
================================ | ||
|
||
.. automodule:: tarantool.types |
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,108 @@ | ||
""" | ||
Additional Tarantool type definitions. | ||
""" | ||
|
||
import typing | ||
from dataclasses import dataclass | ||
|
||
@dataclass | ||
class BoxError(): | ||
""" | ||
Type representing Tarantool `box.error`_ object: a single | ||
MP_ERROR_STACK object with a link to the previous stack error. | ||
.. _box.error: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_error/error/ | ||
""" | ||
|
||
type: typing.Union[str, bytes] | ||
""" | ||
Type that implies source, for example ``"ClientError"``. | ||
Value type depends on :class:`~tarantool.Connection` | ||
:paramref:`~tarantool.Connection.params.encoding`. | ||
""" | ||
|
||
file: typing.Union[str, bytes] | ||
""" | ||
Source code file where error was caught. | ||
Value type depends on :class:`~tarantool.Connection` | ||
:paramref:`~tarantool.Connection.params.encoding`. | ||
""" | ||
|
||
line: int | ||
""" | ||
Line number in source code file. | ||
""" | ||
|
||
message: typing.Union[str, bytes] | ||
""" | ||
Text of reason. | ||
Value type depends on :class:`~tarantool.Connection` | ||
:paramref:`~tarantool.Connection.params.encoding`. | ||
""" | ||
|
||
errno: int | ||
""" | ||
Ordinal number of the error. | ||
""" | ||
|
||
errcode: int | ||
""" | ||
Number of the error as defined in ``errcode.h``. | ||
""" | ||
|
||
fields: typing.Optional[dict] = None | ||
""" | ||
Additional fields depending on error type. For example, if | ||
:attr:`~tarantool.types.BoxError.type` is ``"AccessDeniedError"``, | ||
then it will include ``"object_type"``, ``"object_name"``, | ||
``"access_type"``. | ||
""" | ||
|
||
prev: typing.Optional[typing.List['BoxError']] = None | ||
""" | ||
Previous error in stack. | ||
""" | ||
|
||
|
||
MP_ERROR_STACK = 0x00 | ||
MP_ERROR_TYPE = 0x00 | ||
MP_ERROR_FILE = 0x01 | ||
MP_ERROR_LINE = 0x02 | ||
MP_ERROR_MESSAGE = 0x03 | ||
MP_ERROR_ERRNO = 0x04 | ||
MP_ERROR_ERRCODE = 0x05 | ||
MP_ERROR_FIELDS = 0x06 | ||
|
||
def decode_box_error(err_map): | ||
""" | ||
Decode MessagePack map received from Tarantool to `box.error`_ | ||
object representation. | ||
:param err_map: Error MessagePack map received from Tarantool. | ||
:type err_map: :obj:`dict` | ||
:rtype: :class:`~tarantool.BoxError` | ||
:raises: :exc:`KeyError` | ||
""" | ||
|
||
encoded_stack = err_map[MP_ERROR_STACK] | ||
|
||
prev = None | ||
for item in encoded_stack[::-1]: | ||
err = BoxError( | ||
type=item[MP_ERROR_TYPE], | ||
file=item[MP_ERROR_FILE], | ||
line=item[MP_ERROR_LINE], | ||
message=item[MP_ERROR_MESSAGE], | ||
errno=item[MP_ERROR_ERRNO], | ||
errcode=item[MP_ERROR_ERRCODE], | ||
fields=item.get(MP_ERROR_FIELDS), # omitted if empty | ||
prev=prev, | ||
) | ||
prev = err | ||
|
||
return prev |
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