lua/msgpack: add details to msgpack.decode error
With this patch, mp_check sets diag with detailed information about the MsgPack decoding error. The diag includes the error reason, which is appended to the error message, and the data offset, which is stored in an error payload field. Possible error reasons are: truncated input, junk after input, illegal code, invalid extension. In case of truncated input, the error also includes the trunc_count payload field, which is set to the number of missing MsgPack values. Failing to decode a MsgPack extension adds two payload fields, ext_type and ext_len, and also an error cause, which is set by the extension decoder. For all extensions except the error extension, the error cause is just "cannot unpack FOO". For the error extension, it includes a detailed cause pointing to the error in the MsgPack data stored in the extension. Currently, the mp_check error is reported only by the Lua msgapck decoder while other mp_check users (e.g. xrow decoder) override it. We may improve on this in future. Examples: tarantool> require('msgpack').decode('\x94\xc0') --- - error: Invalid MsgPack - truncated input ... tarantool> box.error.last():unpack() --- - offset: 2 code: 20 base_type: ClientError type: ClientError trunc_count: 3 message: Invalid MsgPack - truncated input trace: - file: ./src/box/msgpack.c line: 151 ... tarantool> require('msgpack').decode(string.char( > 130, 39, 170, 114, 101, 116, 117, 114, 110, 32, 46, > 46, 46, 33, 145, 199, 74, 3, 129, 0, 145, 134, > 0, 171, 67, 108, 105, 101, 110, 116, 69, 114, 114, > 111, 114, 1, 170, 99, 111, 110, 102, 105, 103, 46, > 108, 117, 97, 2, 211, 0, 0, 0, 0, 0, 0, > 0, 201, 3, 173, 85, 110, 107, 110, 111, 119, 110, > 32, 101, 114, 114, 111, 114, 4, 211, 0, 0, 0, > 0, 0, 0, 0, 0, 5, 211, 0, 0, 0, 0, > 0, 0, 0, 0)) --- - error: Invalid MsgPack - invalid extension ... tarantool> box.error.last():unpack() --- - code: 20 base_type: ClientError prev: Invalid MsgPack - cannot unpack error message: Invalid MsgPack - invalid extension ext_len: 74 ext_type: 3 trace: - file: ./src/box/msgpack.c line: 161 type: ClientError offset: 18 ... tarantool> box.error.last().prev:unpack() --- - code: 20 base_type: ClientError type: ClientError prev: Invalid MsgPack - MP_ERROR_LINE value must be MP_UINT message: Invalid MsgPack - cannot unpack error trace: - file: ./src/box/msgpack.c line: 126 ... tarantool> box.error.last().prev.prev:unpack() --- - offset: 30 code: 20 base_type: ClientError type: ClientError message: Invalid MsgPack - MP_ERROR_LINE value must be MP_UINT trace: - file: ./src/box/mp_error.cc line: 350 ... Closes #7968 NO_DOC=error reporting improvement
Showing
- changelogs/unreleased/gh-7968-mp-check-diag.md 7 additions, 0 deletionschangelogs/unreleased/gh-7968-mp-check-diag.md
- src/box/mp_error.cc 73 additions, 65 deletionssrc/box/mp_error.cc
- src/box/msgpack.c 69 additions, 5 deletionssrc/box/msgpack.c
- src/lua/msgpack.c 5 additions, 7 deletionssrc/lua/msgpack.c
- test/app-luatest/msgpack_test.lua 264 additions, 3 deletionstest/app-luatest/msgpack_test.lua
Loading
Please register or sign in to comment