Skip to content
Snippets Groups Projects
Commit 4bcaf15e authored by Nikita Pettik's avatar Nikita Pettik Committed by Kirill Yukhin
Browse files

box: always promote error created via box.error() to diag

This patch makes box.error() always promote error to the diagnostic
area despite of passed arguments.

Closes #4829

@TarantoolBot document
Title: always promote error created via box.error() to diag

box.error() is able to accept two types of argument: either pair of code
and reason (box.error{code = 555, reason = 'Arbitrary message'}) or error
object (box.error(err)). In the first case error is promoted to
diagnostic area, meanwhile in the latter - it is not:
```
e1 = box.error.new({code = 111, reason = "cause"})
box.error({code = 111, reason = "err"})
- error: err
box.error.last()
- err
box.error(e1)
- error: cause
box.error.last()
- err
```
From now box.error(e1) sets error to diagnostic area as well:
```
box.error(e1)
- error: cause
box.error.last()
- cause
```
parent ba7304fb
No related branches found
No related tags found
No related merge requests found
......@@ -114,9 +114,16 @@ luaT_error_call(lua_State *L)
return luaT_error(L);
return 0;
}
if (lua_gettop(L) == 2 && luaL_iserror(L, 2))
return lua_error(L);
struct error *e = luaT_error_create(L, 2);
struct error *e = NULL;
if (lua_gettop(L) == 2) {
e = luaL_iserror(L, 2);
if (e != NULL) {
/* Re-set error to diag area. */
diag_set_error(&fiber()->diag, e);
return lua_error(L);
}
}
e = luaT_error_create(L, 2);
if (e == NULL)
return luaL_error(L, "box.error(): bad arguments");
diag_set_error(&fiber()->diag, e);
......
......@@ -808,3 +808,25 @@ assert(e2.prev == e3)
| ---
| - true
| ...
-- gh-4829: always promote error created via box.error() to
-- diagnostic area.
e1 = box.error.new({code = 111, reason = "cause"})
| ---
| ...
box.error({code = 111, reason = "err"})
| ---
| - error: err
| ...
box.error.last()
| ---
| - err
| ...
box.error(e1)
| ---
| - error: cause
| ...
assert(box.error.last() == e1)
| ---
| - true
| ...
......@@ -221,3 +221,11 @@ e2:set_prev(e3)
box.error.set(e2)
assert(e1.prev == nil)
assert(e2.prev == e3)
-- gh-4829: always promote error created via box.error() to
-- diagnostic area.
e1 = box.error.new({code = 111, reason = "cause"})
box.error({code = 111, reason = "err"})
box.error.last()
box.error(e1)
assert(box.error.last() == e1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment