Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: lvasiliev <lvasiliev@tarantool.org>,
	Alexander Turenko <alexander.turenko@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 1/5] error: Add a Lua backtrace to error
Date: Thu, 16 Apr 2020 02:00:59 +0200	[thread overview]
Message-ID: <831ae724-0d73-916b-0fad-dd52ce967664@tarantool.org> (raw)
In-Reply-To: <c7b5843c-f618-7937-155e-24782fba6bec@tarantool.org>

Hi! Thanks for the fixes!

> On 14.04.2020 4:11, Vladislav Shpilevoy wrote:
>> Thanks for the patch!
>>
>> Sorry, some of my comments may contain typos, because it is
>> very late and I can't continue polishing it today.
>>
>> First of all there are some major issues with the
>> patch, which IMO should be clarified before it is pushed.
>>
>> 1) Why do we need the traceback in scope of 4398? It has
>> nothing to do with marshaling through IProto, nor with
>> custom error types.
> This is part of the errors.lua functional, which was attached as an example. After that it was also one of the functionality requested by Nazarov.

The original ticket does not contain any mentioning of a traceback:
https://github.com/tarantool/tarantool/issues/4398#issue-475632900

I agree that it was requested later, in comments, but still it
looks pretty separate from this, don't you agree?

>> 2) What to do with stacked errors? Currently only the first
>> error in the stack gets a traceback, because luaT_pusherror() is
>> called only on the top error in the stack. Consider this test:
>>
>>      box.cfg{}
>>      lua_code = [[function(tuple)
>>                      local json = require('json')
>>                      return json.encode(tuple)
>>                   end]]
>>      box.schema.func.create('runtimeerror', {body = lua_code, is_deterministic = true, is_sandboxed = true})
>>      s = box.schema.space.create('withdata')
>>      pk = s:create_index('pk')
>>      idx = s:create_index('idx', {func = box.func.runtimeerror.id, parts = {{1, 'string'}}})
>>
>>      function test_func() return pcall(s.insert, s, {1}) end
>>      box.error.cfg{traceback_enable = true}
>>      ok, err = test_func()
>>
>>
>>      tarantool> err:unpack()
>>      ---
>>      - traceback: "stack traceback:\n\t[C]: at 0x010014d1b0\n\t[C]: in function 'test_func'\n\t[string
>>          \"ok, err = test_func()\"]:1: in main chunk\n\t[C]: in function 'pcall'\n\tbuiltin/box/console.lua:382:
>>          in function 'eval'\n\tbuiltin/box/console.lua:676: in function 'repl'\n\tbuiltin/box/console.lua:725:
>>          in function <builtin/box/console.lua:713>"
>>      ... <snipped>
>>
>>      tarantool> err.prev:unpack()
>>      ---
>>      - type: LuajitError
>>        message: '[string "return function(tuple)..."]:2: attempt to call global ''require''
>>          (a nil value)'
>>      ... <snipped>
>>
>> The second error does not have a traceback at all.
> (I added Turenko to To)
> I have two variants:
> - Leave as is and to document such behavior
> - Add the same traceback to all errors in the stack
> Alexander what do you think?

There is a third option - leave traceback out of this patchset for
a next release. Because they are clearly underdesigned. But on the
other hand it is not something critical. After all, we just can say,
that a traceback can be present, or can be not, and its content is
just a string, which can't be assumed to have any special format.

That would allow us to add/remove them and change their format anytime.

>> diff --git a/src/box/lua/error.cc b/src/box/lua/error.cc
>> index 4432bc89b..a616e87a4 100644
>> --- a/src/box/lua/error.cc
>> +++ b/src/box/lua/error.cc
>> @@ -112,9 +112,11 @@ raise:
>>       }
>>         struct error *err = box_error_new(file, line, code, "%s", reason);
>> -    if (tb_parsed)
>> -        err->traceback_mode = tb_mode;
>> -
>> +    /*
>> +     * Explicit traceback option overrides the global setting.
>> +     */
>> +    if (err != NULL && is_traceback_specified)
> 1) box_error_new don't return NULL

True, then 'err != NULL' check can be dropped.

>>   diff --git a/src/lib/core/diag.c b/src/lib/core/diag.c
>> index 1caa75ee9..833454bac 100644
>> --- a/src/lib/core/diag.c
>> +++ b/src/lib/core/diag.c
>> @@ -128,27 +125,14 @@ error_vformat_msg(struct error *e, const char *format, va_list ap)
>> -void
>> -error_set_traceback_supplementation(bool traceback_mode)
>> +error_set_traceback(struct error *e, const char *traceback)
>>   {
>> -    global_traceback_mode = traceback_mode;
>> +    assert(e->traceback == NULL);
> 2) Do I understand correctly that asserts only work on debug? Will this approach not be dangerous by memory leaks on release?

It should not be. Because the method is not public, and
in private methods it is never called with non-zero e->traceback.

>> +    e->traceback = strdup(traceback);
>> +    /*
>> +     * Don't try to set it again. Traceback can be NULL in case of OOM, so
>> +     * it is not a reliable source of information whether need to collect a
>> +     * traceback.
>> +     */
>> +    e->is_traceback_enabled = false;
>>   }
>> diff --git a/src/lib/core/diag.h b/src/lib/core/diag.h
>> index f38009c54..e918d3089 100644
>> --- a/src/lib/core/diag.h
>> +++ b/src/lib/core/diag.h
>> @@ -42,6 +42,13 @@
>>   extern "C" {
>>   #endif /* defined(__cplusplus) */
>>   +/**
>> + * Flag to turn on/off traceback automatic collection. Currently
>> + * it works only for Lua. Stack is collected at the moment of
>> + * error object push onto the stack.
>> + */
>> +extern bool error_is_traceback_enabled;
> 3) Why a global variable is more preferable than static?

Static variables are also global. I just removed the setter, since
it is trivial.

>>   diff --git a/src/lua/error.lua b/src/lua/error.lua
>> index 46d28667f..535110588 100644
>> --- a/src/lua/error.lua
>> +++ b/src/lua/error.lua
>> @@ -26,8 +26,8 @@ struct error {
>>       char _errmsg[DIAG_ERRMSG_MAX];
>>       struct error *_cause;
>>       struct error *_effect;
>> -    char *lua_traceback;
>> -    bool traceback_mode;
>> +    char *traceback;
> 4) Replaced to err_traceback. It overlaps the traceback getter.
>> +    bool is_traceback_enabled;

Better replace it with _traceback. Similar to other members.

  reply	other threads:[~2020-04-16  0:01 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10  8:10 [Tarantool-patches] [PATCH v2 0/5] Extending error functionality Leonid Vasiliev
2020-04-10  8:10 ` [Tarantool-patches] [PATCH v2 1/5] error: Add a Lua backtrace to error Leonid Vasiliev
2020-04-14  1:11   ` Vladislav Shpilevoy
2020-04-15  9:25     ` lvasiliev
2020-04-16  0:00       ` Vladislav Shpilevoy [this message]
2020-04-16  1:11         ` Alexander Turenko
2020-04-16  8:58           ` lvasiliev
2020-04-16  9:30             ` Alexander Turenko
2020-04-16 12:27               ` lvasiliev
2020-04-16 12:45                 ` Alexander Turenko
2020-04-16 17:48                   ` lvasiliev
2020-04-16  8:40         ` lvasiliev
2020-04-16  9:04           ` lvasiliev
2020-04-10  8:10 ` [Tarantool-patches] [PATCH v2 2/5] error: Add the custom error type Leonid Vasiliev
2020-04-14  1:11   ` Vladislav Shpilevoy
2020-04-15  9:25     ` lvasiliev
2020-04-16  0:02       ` Vladislav Shpilevoy
2020-04-16  9:18         ` lvasiliev
2020-04-16 21:03           ` Vladislav Shpilevoy
2020-04-10  8:10 ` [Tarantool-patches] [PATCH v2 3/5] error: Increase the number of fields transmitted through IPROTO Leonid Vasiliev
2020-04-14  1:12   ` Vladislav Shpilevoy
2020-04-15  9:25     ` lvasiliev
2020-04-16  0:02       ` Vladislav Shpilevoy
2020-04-10  8:10 ` [Tarantool-patches] [PATCH v2 4/5] iproto: Add session settings for IPROTO Leonid Vasiliev
2020-04-14  1:12   ` Vladislav Shpilevoy
2020-04-15  9:26     ` lvasiliev
2020-04-16  0:06       ` Vladislav Shpilevoy
2020-04-16  9:36         ` lvasiliev
2020-04-16 21:04           ` Vladislav Shpilevoy
2020-04-10  8:10 ` [Tarantool-patches] [PATCH v2 5/5] iproto: Update error MsgPack encoding Leonid Vasiliev
2020-04-14  1:12   ` Vladislav Shpilevoy
2020-04-15  9:25     ` lvasiliev
2020-04-16  0:11       ` Vladislav Shpilevoy
2020-04-16 10:04         ` lvasiliev
2020-04-16 21:06           ` Vladislav Shpilevoy
2020-04-14  1:10 ` [Tarantool-patches] [PATCH v2 0/5] Extending error functionality Vladislav Shpilevoy
2020-04-15  9:48   ` lvasiliev

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=831ae724-0d73-916b-0fad-dd52ce967664@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=lvasiliev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 1/5] error: Add a Lua backtrace to error' \
    /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