Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Nikita Pettik <korablev@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 3/7] box/error: don't set error created via box.error.new to diag
Date: Sat, 22 Feb 2020 18:18:12 +0100	[thread overview]
Message-ID: <c2b0e527-436f-876d-573e-3f35add455d6@tarantool.org> (raw)
In-Reply-To: <f73a37259ffbe271e9353361f4e04c3190ee9a26.1582119629.git.korablev@tarantool.org>

Thanks for the patch!

See 6 comments below.

On 19/02/2020 15:16, Nikita Pettik wrote:
> To achieve this let's refactor luaT_error_create() to return error
> object instead of setting it via box_error_set().
> luaT_error_created() is used both to handle box.error() and

1. luaT_error_created() -> luaT_error_create().

> box.error.new() invocations, and box.error() is still expected to set
> error to diagnostic area. So, luaT_error_call() which implements
> box.error() processing at the end calls diag_set_error().
> It is worth mentioning that net.box module relied on the fact that
> box.error.new() set error to diagnostic area: otherwise request errors
> don't get to diagnostic area on client side.
> 
> @TarantoolBot document
> Title: Don't promote error created via box.error.new to diagnostic area
> 
> Now box.error.new() only creates error object, but doesn't set it to
> Tarantool's diagnostic area:
> box.error.clear()
> e = box.error.new({code = 111, reason = "cause"})
> assert(box.error.last() == nil)
> ---
> - true
> ...

2. It is better to wrap the code into ```, because otherwise it will
look like tickets created by Peter, with weird formatting, huge headers,
etc.

> To set error in diagnostic area explicitly box.error.set() has been
> introduced. It accepts error object which is set as last system error
> (i.e. becomes available via box.error.last()).
> Finally, box.error.new() does not longer accept error object as an
> argument (this was undocumented feature).
> Note that patch does not affect box.error(), which still pushed error to
> diagnostic area. This fact is reflected in docs:
> '''
> Emulate a request error, with text based on one of the pre-defined
> Tarantool errors...
> '''
> 
> Needed for #1148
> Closes #4778

3. This should be above docbot request. Otherwise it will appear in the
doc ticket.

> ---
>  src/box/error.cc       | 16 +++++++++++++++
>  src/box/error.h        |  8 ++++++++
>  src/box/lua/error.cc   | 56 ++++++++++++++++++++++++++++----------------------
>  test/box/misc.result   | 30 ++++++++++++++++++++++++++-
>  test/box/misc.test.lua | 16 +++++++++++++++
>  5 files changed, 101 insertions(+), 25 deletions(-)
> 
> diff --git a/src/box/error.cc b/src/box/error.cc
> index 7dfe1b3ee..824a4617c 100644
> --- a/src/box/error.cc
> +++ b/src/box/error.cc
> @@ -86,6 +86,22 @@ box_error_set(const char *file, unsigned line, uint32_t code,
>  	return -1;
>  }
>  
> +struct error *
> +box_error_construct(const char *file, unsigned line, uint32_t code,
> +		    const char *fmt, ...)
> +{
> +	struct error *e = BuildClientError(file, line, ER_UNKNOWN);
> +	ClientError *client_error = type_cast(ClientError, e);
> +	if (client_error != NULL) {
> +		client_error->m_errcode = code;

4. You can now make box_error_set() call box_error_construct() +
diag_set(), to avoid code duplication.

> +		va_list ap;
> +		va_start(ap, fmt);
> +		error_vformat_msg(e, fmt, ap);
> +		va_end(ap);
> +	}
> +	return e;
> +}
> +
>  /* }}} */
>  
>  struct rmean *rmean_error = NULL;
> diff --git a/src/box/error.h b/src/box/error.h
> index b8c7cf73d..42043ef80 100644
> --- a/src/box/error.h
> +++ b/src/box/error.h
> @@ -129,6 +129,14 @@ int
>  box_error_set(const char *file, unsigned line, uint32_t code,
>  	      const char *format, ...);
>  
> +/**
> + * Construct error object without setting it in the diagnostics
> + * area. On the memory allocation fail returns NULL.
> + */
> +struct error *
> +box_error_construct(const char *file, unsigned line, uint32_t code,
> +		    const char *fmt, ...);

5. You added the method to the public C API (it is inside 'cond public'
comments). I don't think we should do that. At least until someone
asked so.

Also why not box_error_new()? 'Construct' seems to be a very strange name.

> +
>  /**
>   * A backward-compatible API define.
>   */
> diff --git a/src/box/lua/error.cc b/src/box/lua/error.cc
> index 7311cb2ce..17d4de653 100644
> --- a/src/box/lua/error.cc
> +++ b/src/box/lua/error.cc
> @@ -42,7 +42,14 @@ extern "C" {
>  #include "lua/utils.h"
>  #include "box/error.h"
>  
> -static void
> +/**
> + * Parse Lua arguments (they can come as single table
> + * f({code : number, reason : string}) or as separate members
> + * f(code, reason)) and construct struct error with given values.
> + * In case one of arguments is missing it corresponding field

6. it -> its.

> + * in struct error is filled with default value.
> + */
> +static struct error *
>  luaT_error_create(lua_State *L, int top_base)
>  {
>  	uint32_t code = 0;

  reply	other threads:[~2020-02-22 17:18 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19 14:16 [Tarantool-patches] [PATCH 0/7] Stacked diagnostics area Nikita Pettik
2020-02-19 14:16 ` [Tarantool-patches] [PATCH 1/7] box: rename diag_add_error to diag_set_error Nikita Pettik
2020-02-19 14:16 ` [Tarantool-patches] [PATCH 2/7] box/error: introduce box.error.set() method Nikita Pettik
2020-02-19 14:26   ` Cyrill Gorcunov
2020-02-19 14:30     ` Nikita Pettik
2020-02-19 14:53       ` Cyrill Gorcunov
2020-02-19 14:16 ` [Tarantool-patches] [PATCH 3/7] box/error: don't set error created via box.error.new to diag Nikita Pettik
2020-02-22 17:18   ` Vladislav Shpilevoy [this message]
2020-03-25  1:02     ` Nikita Pettik
2020-03-26  0:22       ` Vladislav Shpilevoy
2020-03-26  1:03         ` Nikita Pettik
2020-02-19 14:16 ` [Tarantool-patches] [PATCH 4/7] box: introduce stacked diagnostic area Nikita Pettik
2020-02-19 21:10   ` Vladislav Shpilevoy
2020-02-20 11:53     ` Nikita Pettik
2020-02-20 18:29       ` Nikita Pettik
2020-02-23 17:43   ` Vladislav Shpilevoy
2020-03-25  1:34     ` Nikita Pettik
2020-02-19 14:16 ` [Tarantool-patches] [PATCH 5/7] box/error: clarify purpose of reference counting in struct error Nikita Pettik
2020-02-23 17:43   ` Vladislav Shpilevoy
2020-03-25  1:40     ` Nikita Pettik
2020-02-19 14:16 ` [Tarantool-patches] [PATCH 6/7] iproto: refactor error encoding with mpstream Nikita Pettik
2020-02-23 17:44   ` Vladislav Shpilevoy
2020-03-25  1:42     ` Nikita Pettik
2020-02-19 14:16 ` [Tarantool-patches] [PATCH 7/7] iproto: support error stacked diagnostic area Nikita Pettik
2020-02-23 17:43   ` Vladislav Shpilevoy
2020-03-25  1:38     ` Nikita Pettik
2020-02-22 17:18 ` [Tarantool-patches] [PATCH 0/7] Stacked diagnostics area Vladislav Shpilevoy

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=c2b0e527-436f-876d-573e-3f35add455d6@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 3/7] box/error: don'\''t set error created via box.error.new 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