[Tarantool-patches] [PATCH 3/9] error: move code to struct error from ClientError

Serge Petrenko sergepetrenko at tarantool.org
Fri Nov 12 09:31:44 MSK 2021



12.11.2021 02:50, Vladislav Shpilevoy пишет:
> Thanks for the review!
>
>>> diff --git a/src/lua/error.lua b/src/lua/error.lua
>>> index ebc784f07..9fb227df4 100644
>>> --- a/src/lua/error.lua
>>> +++ b/src/lua/error.lua
>>> @@ -18,6 +18,7 @@ struct error {
>>>        const struct type_info *_type;
>>>        int64_t _refs;
>>>        int _saved_errno;
>>> +    int code;
>> 1. All the other fields are prefixed with "_" for some reason.
>>     Let's do the same for "code", just to comply.
> I named it without '_' intentionally. Because then Lua will see
> this field right away when you do `err.code`. That also allows
> me not to define a getter in `error_fields` table.
>
>>>        /** Line number. */
>>>        unsigned _line;
>>>        /* Source file name. */
>>> @@ -158,7 +159,7 @@ local function error_unpack(err)
>>>        if not ffi.istype('struct error', err) then
>>>            error("Usage: error:unpack()")
>>>        end
>>> -    local result = {}
>>> +    local result = {code = err.code}
>> 2. Why not add 'code' to 'error_fields' ?
> Because it is visible without a getter anyway. On the downside, here
> in unpack() I need to add it explicitly.

Ok. Thanks for the explanation!


-- 
Serge Petrenko



More information about the Tarantool-patches mailing list