Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: imeevma@tarantool.org
Cc: kostja@tarantool.org, tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: rework error handling in box.execute()
Date: Tue, 30 Jul 2019 22:45:05 +0200	[thread overview]
Message-ID: <e7a00076-761c-a54d-3218-531894e63669@tarantool.org> (raw)
In-Reply-To: <3a3334974edb35becea5ca606d2943a230f097a4.1564495334.git.imeevma@gmail.com>

Hi! Thanks for the patch!

On 30/07/2019 16:04, imeevma@tarantool.org wrote:
> In accordance with the Lua coding style in Tarantool, all errors
> returned in Lua should be returned using 'return nil, error'.
> However, box.execute() throws an exception in case of an error.
> This patch causes box.execute() to return an error, as described
> in the coding style.
> 
> Closes #4390
> ---
> https://github.com/tarantool/tarantool/issues/4390
> https://github.com/tarantool/tarantool/tree/imeevma/gh-4390-box_execute-should-not-throw
> 
> diff --git a/src/box/lua/execute.c b/src/box/lua/execute.c
> index 7b7c575..85c5738 100644
> --- a/src/box/lua/execute.c
> +++ b/src/box/lua/execute.c
> @@ -254,13 +254,25 @@ lbox_execute(struct lua_State *L)
>  		if (! lua_istable(L, 2))
>  			return luaL_error(L, "Second argument must be a table");
>  		bind_count = lua_sql_bind_list_decode(L, &bind, 2);
> -		if (bind_count < 0)
> -			return luaT_error(L);
> +		if (bind_count < 0) {
> +			lua_pushnil(L);
> +			struct error *e = box_error_last();
> +			if (e == NULL)
> +				return 1;
> +			luaT_pusherror(L, e);

First, how is it possible, that e == NULL? It should not be
so. I deleted that check, and the tests passed. So please,
drop it.

Secondly, there are already 4 places, which push exactly the same
nil + diag error. And 13 more intricate places in lua/fio.c.
I propose you to introduce a new function to push nil + last box
error.

Another place is lua_swim_new, which pushes nil implicitly,
when in the expression:

    *(struct swim **) luaL_pushcdata(L, ctid_swim_ptr) = s;

's' is NULL. But in fact it is the same case, and here you can
use than new function too.

Please, introduce and use that new function in a separate commit
before this one.

      reply	other threads:[~2019-07-30 20:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-30 14:04 [tarantool-patches] " imeevma
2019-07-30 20:45 ` Vladislav Shpilevoy [this message]

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=e7a00076-761c-a54d-3218-531894e63669@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v1 1/1] sql: rework error handling in box.execute()' \
    /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