Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Cc: v.shpilevoy@tarantool.org
Subject: [Tarantool-patches] [PATCH v3 5/6] box: always promote error created via box.error() to diag
Date: Mon,  6 Apr 2020 17:17:14 +0300	[thread overview]
Message-ID: <67e17e1bfa4f8ae989aa176b50b57b155a667935.1586181413.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1586181413.git.korablev@tarantool.org>
In-Reply-To: <cover.1586181413.git.korablev@tarantool.org>

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
```
---
 src/box/lua/error.cc    | 13 ++++++++++---
 test/box/error.result   | 22 ++++++++++++++++++++++
 test/box/error.test.lua |  8 ++++++++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/src/box/lua/error.cc b/src/box/lua/error.cc
index 08c2d983d..b2625bf5f 100644
--- a/src/box/lua/error.cc
+++ b/src/box/lua/error.cc
@@ -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);
diff --git a/test/box/error.result b/test/box/error.result
index 3d07f6e64..234c26371 100644
--- a/test/box/error.result
+++ b/test/box/error.result
@@ -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
+ | ...
diff --git a/test/box/error.test.lua b/test/box/error.test.lua
index ed7eb7565..41baed52d 100644
--- a/test/box/error.test.lua
+++ b/test/box/error.test.lua
@@ -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)
-- 
2.17.1

  parent reply	other threads:[~2020-04-06 14:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06 14:17 [Tarantool-patches] [PATCH v3 0/6] Stacked diagnostics Nikita Pettik
2020-04-06 14:17 ` [Tarantool-patches] [PATCH v3 1/6] box: introduce stacked diagnostic area Nikita Pettik
2020-04-06 14:17 ` [Tarantool-patches] [PATCH v3 2/6] box: use stacked diagnostic area for functional indexes Nikita Pettik
2020-04-06 14:17 ` [Tarantool-patches] [PATCH v3 3/6] box/error: clarify purpose of reference counting in struct error Nikita Pettik
2020-04-06 14:17 ` [Tarantool-patches] [PATCH v3 4/6] iproto: refactor error encoding with mpstream Nikita Pettik
2020-04-06 14:17 ` Nikita Pettik [this message]
2020-04-06 14:17 ` [Tarantool-patches] [PATCH v3 6/6] iproto: support error stacked diagnostic area Nikita Pettik
2020-04-07 11:13 ` [Tarantool-patches] [PATCH v3 0/6] Stacked diagnostics Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67e17e1bfa4f8ae989aa176b50b57b155a667935.1586181413.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v3 5/6] box: always promote error created via box.error() to diag' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox