iproto: support error stacked diagnostic area
This patch introduces support of stacked errors in IProto protocol and in net.box module. Closes #1148 @TarantoolBot document Title: Stacked error diagnostic area Starting from now errors can be organized into lists. To achieve this Lua table representing error object is extended with .prev field and e:set_prev(err) method. .prev field returns previous error if any exist. e:set_prev(err) method expects err to be error object or nil and sets err as previous error of e. For instance: ``` e1 = box.error.new({code = 111, reason = "cause"}) e2 = box.error.new({code = 111, reason = "cause of cause"}) e1:set_prev(e2) assert(e1.prev == e2) -- true ``` Cycles are not allowed for error lists: ``` e2:set_prev(e1) - error: 'builtin/error.lua: Cycles are not allowed' ``` Nil is valid input to :set_prev() method: ``` e1:set_prev(nil) assert(e1.prev == nil) -- true ``` Note that error can be 'previous' only to the one error at once: ``` e1:set_prev(e2) e3:set_prev(e2) assert(e1.prev == nil) -- true assert(e3.prev == e2) -- true ``` Setting previous error does not erase its own previous members: ``` -- e1 -> e2 -> e3 -> e4 e1:set_prev(e2) e2:set_prev(e3) e3:set_prev(e4) e2:set_prev(e5) -- Now there are two lists: e1->e2->e5 and e3->e4 assert(e1.prev == e2) -- true assert(e2.prev == e5) -- true assert(e3.prev == e4) -- true ``` Alternatively: ``` e1:set_prev(e2) e2:set_prev(e3) e3:set_prev(e4) e5:set_prev(e3) -- Now there are two lists: e1->e2 and e5->e3->e4 assert(e1.prev == e2) -- true assert(e2.prev == nil) -- true assert(e5.prev == e3) -- true assert(e3.prev == e4) -- true `` Stacked diagnostics is also supported by IProto protocol. Now responses containing errors always (even if there's only one error to be returned) include new IProto key: IPROTO_ERROR_STACK (0x51). So, body corresponding to error response now looks like: ``` MAP{IPROTO_ERROR : string, IPROTO_ERROR_STACK : ARRAY[MAP{ERROR_CODE : uint, ERROR_MESSAGE : string}, MAP{...}, ...]} ``` where IPROTO_ERROR is 0x31 key, IPROTO_ERROR_STACK is 0x52, ERROR_CODE is 0x01 and ERROR_MESSAGE is 0x02. Instances of older versions (without support of stacked errors in protocol) simply ignore unknown keys and still rely only on IPROTO_ERROR key.
Showing
- src/box/error.cc 21 additions, 0 deletionssrc/box/error.cc
- src/box/error.h 16 additions, 0 deletionssrc/box/error.h
- src/box/iproto_constants.h 6 additions, 0 deletionssrc/box/iproto_constants.h
- src/box/lua/net_box.lua 27 additions, 3 deletionssrc/box/lua/net_box.lua
- src/box/xrow.c 74 additions, 6 deletionssrc/box/xrow.c
- test/box-py/iproto.result 3 additions, 3 deletionstest/box-py/iproto.result
- test/box-py/iproto.test.py 3 additions, 3 deletionstest/box-py/iproto.test.py
- test/box/iproto.result 142 additions, 0 deletionstest/box/iproto.result
- test/box/iproto.test.lua 66 additions, 0 deletionstest/box/iproto.test.lua
- test/box/net.box.result 71 additions, 0 deletionstest/box/net.box.result
- test/box/net.box.test.lua 31 additions, 0 deletionstest/box/net.box.test.lua
- test/unit/xrow.cc 183 additions, 1 deletiontest/unit/xrow.cc
- test/unit/xrow.result 25 additions, 2 deletionstest/unit/xrow.result
Loading
Please register or sign in to comment