box: introduce stacked diagnostic area
In terms of implementation, now struct error objects can be organized into double-linked lists. To achieve this pointers to the next and previous elements (cause and effect correspondingly) have been added to struct error. It is worth mentioning that already existing rlist and stailq list implementations are not suitable: rlist is cycled list, as a result it is impossible to start iteration over the list from random list entry and finish it at the logical end of the list; stailq is single-linked list leaving no possibility to remove elements from the middle of the list. As a part of C interface, box_error_add() has been introduced. In contrast to box_error_set() it does not replace last raised error, but instead it adds error to the list of diagnostic errors having already been set. If error is to be deleted (its reference counter hits 0 value) it is unlinked from the list it belongs to and destroyed. Meanwhile, error destruction leads to decrement of reference counter of its previous error and so on. To organize errors into lists in Lua, table representing error object in Lua now has .prev field (corresponding to 'previous' error) and method :set_prev(e). The latter accepts error object (i.e. created via box.error.new() or box.error.last()) and nil value. Both field .prev and :set_prev() method are implemented as ffi functions. Also note that cycles are not allowed while organizing errors into lists: e1 -> e2 -> e3; e3:set_prev(e1) -- would lead to error. Part of #1148
Showing
- extra/exports 1 addition, 0 deletionsextra/exports
- src/lib/core/diag.c 47 additions, 0 deletionssrc/lib/core/diag.c
- src/lib/core/diag.h 99 additions, 3 deletionssrc/lib/core/diag.h
- src/lib/core/exception.cc 1 addition, 0 deletionssrc/lib/core/exception.cc
- src/lua/error.lua 32 additions, 0 deletionssrc/lua/error.lua
- test/box/error.result 303 additions, 0 deletionstest/box/error.result
- test/box/error.test.lua 112 additions, 0 deletionstest/box/error.test.lua
Loading
Please register or sign in to comment