Tarantool development patches archive
 help / color / mirror / Atom feed
From: lvasiliev <lvasiliev@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH V4 1/6] error: add custom error type
Date: Sat, 18 Apr 2020 20:14:06 +0300	[thread overview]
Message-ID: <71694537-8ac1-471e-2034-224e7434b600@tarantool.org> (raw)
In-Reply-To: <d4fff7d8-9e8c-069a-6507-25e3ea621c04@tarantool.org>

Hi! Thanks for the review.

On 17.04.2020 3:49, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> See 2 comments below.
> 
> On 16/04/2020 19:38, Leonid Vasiliev wrote:
>> Co-authored-by: Vladislav Shpilevoy<v.shpilevoy@tarantool.org>
>>
>> Part of #4398
>>
>> @TarantoolBot document
>> Title: Custom error types for Lua errors
>>
>> Errors can be created in 2 ways: `box.error.new()` and `box.error()`.
>>
>> Both used to take either `code, reason, <reason string args>` or
>> `{code = code, reason = reason, ...}` arguments.
>>
>> Now in the first option instead of code a user can specify a
>> string as its own error type. In the second option a user can
>> specify both code and type. For example:
>>
>> ```Lua
>> box.error('MyErrorType', 'Message')
>> box.error({type = 'MyErrorType', code = 1024, reason = 'Message'})
>> ```
>> Or no-throw version:
>> ```Lua
>> box.error.new('MyErrorType', 'Message')
>> box.error.new({type = 'MyErrorType', code = 1024, reason = 'Message'})
>> ```
>> When a custom type is specified, it is shown in `err.type`
>> attribute. When it is not specified, `err.type` shows one of
>> built-in errors such as 'ClientError', 'OurOfMemory', etc.
>>
>> Name length limit on the custom type is 63 bytes. All is longer
>> is truncated.
> 
> 1. I changed 'All is longer' -> 'All what is longer'. Force
> pushed.
> 
Ok.
>> diff --git a/extra/exports b/extra/exports
>> index a9add2c..9467398 100644
>> --- a/extra/exports
>> +++ b/extra/exports
>> @@ -235,6 +235,7 @@ box_index_min
>>   box_index_max
>>   box_index_count
>>   box_error_type
>> +box_error_custom_type
>>   box_error_code
>>   box_error_message
>>   box_error_last
>> diff --git a/src/box/errcode.h b/src/box/errcode.h
>> index d1e4d02..e37b7bd 100644
>> --- a/src/box/errcode.h
>> +++ b/src/box/errcode.h
>> @@ -266,6 +266,7 @@ struct errcode_record {
>>   	/*211 */_(ER_WRONG_QUERY_ID,		"Prepared statement with id %u does not exist") \
>>   	/*212 */_(ER_SEQUENCE_NOT_STARTED,		"Sequence '%s' is not started") \
>>   	/*213 */_(ER_NO_SUCH_SESSION_SETTING,	"Session setting %s doesn't exist") \
>> +	/*214 */_(ER_CUSTOM_ERROR,		"%s") \
> 
> 2. We discussed that with Alexander - what to do with error codes.
> Because there are 3 options:
> 
> - CustomErrors don't have a code. Only type name. Code will be
>    added later as a part of payload. In that case the syntax:
> 
>        box.error.new({code = 123, type = 'MyType'})
> 
>    becomes illegal. 'error.code' returns nil in Lua for CustomError
>    objects. And CustomError should not be a descendant of ClientError
>    in our code.
> 
> 
> - CustomError has a code, it is always 214. Syntax with custom error
>    code is banned too. But 'error.code' is 214 always. Which is weird.
>    214 is a very strange number, and it creates an unnecessary link
>    with box.error.* codes, which are valid only for ClientErrors.
> 
> 
> - CustomError has a code and a user can choose it. By default it is 0.
> 
> 
> Now the patch is neither of this. You allow to specify code in
> box.error.new() and box.error(), but it is silently ignored and
> replaced with 214.
> 
>  From what I understand, Alexander wants one of the versions above.
> Certainly not the one where we ignore code argument in box.error.new()
> and box.error() functions.
> 
> I am for the last option. So when you write
> 
>      box.error.new({code = 123, type = 'MyType'})
> 
> You can take 'error.code' and it is 123.
> 
> That is the simplest solution in terms of implementation, and the
> simplest in terms of the API. Because you have single format for all
> errors:
> 
>      {type = ..., code = ..., reason = ...}
> 
> Where type and code are optional. If we go for any other option,
> we will need to split it in 2 versions: either
> 
>      {type = ..., reason = ...}
> 
> or
> 
>      {code = ..., reason = ...}
> 
> One can argue, that error codes can intersect, but the thing
> is that ClientError and CustomError are different types for a user.
> box.error.* codes are valid only and only for ClientError objects.
> 
> Moreover, even now I can specify not existing codes when create a
> ClientError object. So intersection argument does not work - codes
> can intersect even now. And it seems to be not a problem.
> 
> Just consider this example:
> 
>      tarantool> args = {code = 214, reason = 'Message'}
>      ---
>      ...
> 
>      tarantool> err = box.error.new(args)
>      ---
>      ...
> 
>      tarantool> err:unpack()
>      ---
>      - code: 214
>        base_type: ClientError
>        type: ClientError
>        message: Message
>        trace:
>        - file: '[string "err = box.error.new(args)"]'
>          line: 1
>      ...
> 
> I created a ClientError with code 214. Not CustomError. ClientError.
> It means, that code is never going to be enough to detect error type.
> You will never be able to compare code with 214, and if they are
> equal, say that it is CustomError. The example above proves it is not
> true. You always need to look at error type first. Therefore it makes
> no sense to ban codes for CustomErrors. It won't protect from anything.
> Updated, now the CustomError code is independent of the ClientError code.

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

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16 17:38 [Tarantool-patches] [PATCH V4 0/6] Extending error functionality Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 1/6] error: add custom error type Leonid Vasiliev
2020-04-17  0:49   ` Vladislav Shpilevoy
2020-04-18 17:14     ` lvasiliev [this message]
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 2/6] error: send custom type in IProto Leonid Vasiliev
2020-04-17  0:51   ` Vladislav Shpilevoy
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 3/6] session: add offset to SQL session settings array Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 4/6] error: add session setting for error type marshaling Leonid Vasiliev
2020-04-16 19:48   ` Konstantin Osipov
2020-04-17  0:51     ` Vladislav Shpilevoy
2020-04-17  7:35       ` Konstantin Osipov
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 5/6] error: update constructors of some errors Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 6/6] error: add error MsgPack encoding Leonid Vasiliev
2020-04-17  0:58   ` Vladislav Shpilevoy
2020-04-18 17:46     ` lvasiliev
2020-04-17  0:51 ` [Tarantool-patches] [PATCH V4 0/6] Extending error functionality 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=71694537-8ac1-471e-2034-224e7434b600@tarantool.org \
    --to=lvasiliev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH V4 1/6] error: add custom error type' \
    /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