Tarantool development patches archive
 help / color / mirror / Atom feed
From: Eugene Blikh <bigbes@gmail.com>
To: tarantool-patches@freelists.org
Cc: Eugine Blikh <bigbes@gmail.com>
Subject: [tarantool-patches] [PATCH tarantool 2/2] Using luaT_tolstring in conversion function, instead lua_tostring
Date: Mon,  6 Aug 2018 10:17:00 +0300	[thread overview]
Message-ID: <2a49d596262a59a2ee1846d67926bc52a795e048.1533292738.git.bigbes@gmail.com> (raw)
In-Reply-To: <cover.1533292738.git.bigbes@gmail.com>
In-Reply-To: <cover.1533292738.git.bigbes@gmail.com>

From: Eugine Blikh <bigbes@gmail.com>

We can throw any Lua object as Lua error, but current behaviour won't
convert it to string. So diag error's object will have NULL, instead of
string.

luaT_tolstring honors __tostring metamethod and thus can convert table
to it's string representation.

For example, old behaviour is:
```
tarantool> fiber.create(error, 'help')
LuajitError: help
tarantool> fiber.create(error, { message = 'help' })
LuajitError:
tarantool> fiber.create(error, setmetatable({ message = 'help' }, {
                          __tostring = function(self) return self.message end
                        }))
LuajitError:
```

New behaviour is:
```
tarantool> fiber.create(error, 'help')
LuajitError: help
tarantool> fiber.create(error, { 'help' })
LuajitError: table: 0x0108fa2790
tarantool> fiber.create(error, setmetatable({ message = 'help' }, {
                          __tostring = function(self) return self.message end
                        }))
LuajitError: help
```

It won't break anything, but'll add new behaviour
---
 src/lua/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lua/utils.c b/src/lua/utils.c
index afc44b581..56df2bfb6 100644
--- a/src/lua/utils.c
+++ b/src/lua/utils.c
@@ -920,7 +920,7 @@ luaT_toerror(lua_State *L)
 		diag_add_error(&fiber()->diag, e);
 	} else {
 		/* Convert Lua error to a Tarantool exception. */
-		diag_set(LuajitError, lua_tostring(L, -1));
+		diag_set(LuajitError, luaT_tolstring(L, -1, NULL));
 	}
 	return 1;
 }
-- 
2.16.2

      parent reply	other threads:[~2018-08-06  7:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-06  7:16 [tarantool-patches] [PATCH tarantool 0/2] Using luaT_tolstring in error " Eugene Blikh
2018-08-06  7:16 ` [tarantool-patches] [PATCH tarantool 1/2] Introduce luaT_tolstring Eugene Blikh
2018-08-06  7:17 ` Eugene Blikh [this message]

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=2a49d596262a59a2ee1846d67926bc52a795e048.1533292738.git.bigbes@gmail.com \
    --to=bigbes@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH tarantool 2/2] Using luaT_tolstring in conversion function, instead lua_tostring' \
    /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