From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 491DC469710 for ; Mon, 1 Jun 2020 15:54:44 +0300 (MSK) References: <8cfa7e20-d067-f77d-4300-0b228ad6e440@tarantool.org> From: Leonid Vasiliev Message-ID: <63a5bca5-45a6-0f3f-d361-60db93c42941@tarantool.org> Date: Mon, 1 Jun 2020 15:54:43 +0300 MIME-Version: 1.0 In-Reply-To: <8cfa7e20-d067-f77d-4300-0b228ad6e440@tarantool.org> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [Tarantool-patches] [PATCH] error: add format string usage to form a CustomError message List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Hi! Thank you for the review. I updated the commit message: error: add format string usage to compose a CustomError message For the CustomError the ability to create a message using a format string was added. Closes #4903 @TarantoolBot document Title: Add format string usage to compose a CustomError message When an error created using the separate members mode (box.error(code, errtext[, errtext ...])) in the case of ClientError error creation, a pre-defined format is used (corresponding to the error code) (nothing has changed), in the case of CustomError error creation, a format string can be used to compose a message. ClientError(nothing has changed): ```Lua box.error(code, reason args) ``` Example for ER_CREATE_SPACE: ```Lua box.error(9, "my_space", "reason") ``` Result: ```Lua error: 'Failed to create space ''my_space'': reason' ``` CustomError: ```Lua box.error(type, reason format string, reason args) ``` Example: ```Lua box.error("MyCustomType", "The error reason: %s", "some error reason") ``` Result: ```Lua error: 'The error reason: some error reason' ``` On 30.05.2020 01:05, Vladislav Shpilevoy wrote: > Hi! Thanks for the patch! > > On 28/05/2020 10:31, Leonid Vasiliev wrote: >> For the CustomError the ability to create a message >> using a format string was added. >> >> Closes #4903 >> >> @TarantoolBot document >> Title: Add format string usage to form a CustomError message >> When creating a ClientError error the predefined format >> (corresponding with the error code) is used. >> When creating a CustomError error a format string can be >> used to form the message. >> >> ClientError: >> ```Lua >> box.error(code, reason args) >> ``` >> >> CustomError: >> ```Lua >> box.error(type, reason format string, reason args) >> ``` > > It would be good to provide an example here. And to state, that > client error case is not changed. Otherwise from the text above > it looks like you changed it to be 'the predefined format is used'. > But I will leave it to the doc team to ping you after this is > pushed. > > Talking of the client error formatting correctness, it looks like > currently the documentation says: > https://www.tarantool.io/en/doc/2.3/reference/reference_lua/box_error/#lua-function.box.error > > When called with a Lua-table argument, the code and reason have any user-desired values. The result will be those values. > > Parameters: > > reason (string) – description of an error, defined by user > code (integer) – numeric code for this error, defined by user > > So in the site it is said, that 'reason' is defined by user, not be > a predefined internal format. The predefined format is used in > box.error(code, ...) syntax. > >> --- >> https://github.com/tarantool/tarantool/issues/4903 >> https://github.com/tarantool/tarantool/tree/lvasiliev/gh-4903-format-string-for-CustomError >> @ChangeLog Add format string usage to form a CustomError message