From: Chris Sosnin <k.sosnin@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v2] box: frommap() bug fix
Date: Thu, 28 Nov 2019 00:30:36 +0300 [thread overview]
Message-ID: <20191127213037.94837-1-k.sosnin@tarantool.org> (raw)
Thank you for the review!
Fixed version below.
branch: https://github.com/tarantool/tarantool/tree/ksosnin/gh-4262-frommap-error-handle
issue: https://github.com/tarantool/tarantool/issues/4262
- If an optional argument is provided for
space_object:frommap() (which is {table = true|false}),
type match for first arguments is omitted, which is
incorrect. We should return the result only after making
sure it is possible to build a tuple.
- If there is a type mismatch, however, frommap() does not
return nil, err as it is mentioned in the description, so we
change it to be this way.
Closes #4262
---
src/box/lua/space.cc | 13 +++++++++----
test/box/tuple.result | 8 +++++++-
test/box/tuple.test.lua | 1 +
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
index f6e96f0c0..e772a924d 100644
--- a/src/box/lua/space.cc
+++ b/src/box/lua/space.cc
@@ -580,14 +580,19 @@ lbox_space_frommap(struct lua_State *L)
}
lua_rawseti(L, -3, fieldno+1);
}
- if (table)
- return 1;
lua_replace(L, 1);
lua_settop(L, 1);
tuple = luaT_tuple_new(L, -1, space->format);
- if (tuple == NULL)
- return luaT_error(L);
+ if (tuple == NULL) {
+ struct error *e = diag_last_error(&fiber()->diag);
+ lua_pushnil(L);
+ lua_pushstring(L, e->errmsg);
+ return 2;
+ }
+ if (table) {
+ return 1;
+ }
luaT_pushtuple(L, tuple);
return 1;
usage_error:
diff --git a/test/box/tuple.result b/test/box/tuple.result
index 9140211b7..78f919deb 100644
--- a/test/box/tuple.result
+++ b/test/box/tuple.result
@@ -1121,7 +1121,13 @@ s:frommap()
...
s:frommap({})
---
-- error: Tuple field 1 required by space format is missing
+- null
+- Tuple field 1 required by space format is missing
+...
+s:frommap({ddd = 'fail', aaa = 2, ccc = 3, bbb = 4}, {table=true})
+---
+- null
+- 'Tuple field 4 type does not match one required by operation: expected unsigned'
...
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = true})
---
diff --git a/test/box/tuple.test.lua b/test/box/tuple.test.lua
index 3ac2902fe..baf2f22d5 100644
--- a/test/box/tuple.test.lua
+++ b/test/box/tuple.test.lua
@@ -373,6 +373,7 @@ s:frommap({ddd = 1, aaa = 2, bbb = 3})
s:frommap({ddd = 1, aaa = 2, ccc = 3, eee = 4})
s:frommap()
s:frommap({})
+s:frommap({ddd = 'fail', aaa = 2, ccc = 3, bbb = 4}, {table=true})
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = true})
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = 4}, {table = false})
s:frommap({ddd = 1, aaa = 2, ccc = 3, bbb = box.NULL})
--
2.21.0 (Apple Git-122.2)
next reply other threads:[~2019-11-27 21:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-27 21:30 Chris Sosnin [this message]
2019-11-27 21:30 ` [Tarantool-patches] [PATCH v2] build: GCC warning on strncpy Chris Sosnin
2019-11-27 23:40 ` Vladislav Shpilevoy
2019-12-16 13:40 ` Kirill Yukhin
2019-11-27 23:40 ` [Tarantool-patches] [PATCH v2] box: frommap() bug fix 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=20191127213037.94837-1-k.sosnin@tarantool.org \
--to=k.sosnin@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v2] box: frommap() bug fix' \
/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