Skip to content

Commit 530aa82

Browse files
nshylocker
authored andcommitted
error: finish changes to several C modules to use box.error
We already do some steps to use box.error in these C modules. Let's finish it to make a clear distinction between C modules that are switched to box.error and that are not. Follow-up tarantool#9996 NO_CHANGELOG=internal NO_DOC=internal
1 parent dd0ac81 commit 530aa82

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

src/box/lua/call.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,10 @@ lbox_func_call(struct lua_State *L)
10891089
{
10901090
if (box_check_configured() != 0)
10911091
return luaT_error(L);
1092-
if (lua_gettop(L) < 1 || !lua_isstring(L, 1))
1093-
return luaL_error(L, "Use func:call(...)");
1092+
if (lua_gettop(L) < 1 || !lua_isstring(L, 1)) {
1093+
diag_set(IllegalParams, "Use func:call(...)");
1094+
return luaT_error(L);
1095+
}
10941096

10951097
size_t name_len;
10961098
const char *name = lua_tolstring(L, 1, &name_len);

src/box/lua/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ lbox_iterator_next(lua_State *L)
372372
static int
373373
lbox_truncate(struct lua_State *L)
374374
{
375-
uint32_t space_id = luaL_checkinteger(L, 1);
375+
uint32_t space_id = luaT_checkint(L, 1);
376376
if (box_truncate(space_id) != 0)
377377
return luaT_error(L);
378378
return 0;

src/box/lua/init.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,11 @@ lbox_rollback_to_savepoint(struct lua_State *L)
581581
struct txn_savepoint *svp;
582582

583583
if (lua_gettop(L) != 1 ||
584-
(svp = luaT_check_txn_savepoint(L, 1, &svp_txn_id)) == NULL)
585-
return luaL_error(L,
586-
"Usage: box.rollback_to_savepoint(savepoint)");
584+
(svp = luaT_check_txn_savepoint(L, 1, &svp_txn_id)) == NULL) {
585+
diag_set(IllegalParams,
586+
"Usage: box.rollback_to_savepoint(savepoint)");
587+
return luaT_error(L);
588+
}
587589

588590
/*
589591
* Verify that we're in a transaction and that it is the
@@ -710,9 +712,10 @@ lbox_on_##name(struct lua_State *L) { \
710712
struct txn *txn = in_txn(); \
711713
int top = lua_gettop(L); \
712714
if (top > 3 || txn == NULL) { \
713-
return luaL_error(L, "Usage inside a transaction: " \
714-
"box.on_" #name "([new_function | nil, " \
715-
"[old_function | nil], [name | nil]])"); \
715+
diag_set(IllegalParams, "Usage inside a transaction: " \
716+
"box.on_" #name "([new_function | nil, " \
717+
"[old_function | nil], [name | nil]])"); \
718+
return luaT_error(L); \
716719
} \
717720
txn_init_triggers(txn); \
718721
return lbox_trigger_reset(L, 1, &txn->on_##name, lbox_push_txn, NULL); \
@@ -839,8 +842,11 @@ luamp_decode_extension_box(struct lua_State *L, const char **data,
839842
switch (ext_type) {
840843
case MP_ERROR: {
841844
struct error *err = error_unpack(data, len);
842-
if (err == NULL)
843-
luaL_error(L, "Can not parse an error from MsgPack");
845+
if (err == NULL) {
846+
diag_set(IllegalParams,
847+
"Can not parse an error from MsgPack");
848+
luaT_error(L);
849+
}
844850
luaT_pusherror(L, err);
845851
break;
846852
}
@@ -858,12 +864,14 @@ luamp_decode_extension_box(struct lua_State *L, const char **data,
858864
luaT_pushtuple(L, tuple);
859865
break;
860866
tuple_err:
861-
luaL_error(L, "Can not parse a tuple from MsgPack");
867+
diag_set(IllegalParams, "Can not parse a tuple from MsgPack");
868+
luaT_error(L);
862869
break;
863870
}
864871
default:
865-
luaL_error(L, "Unsupported MsgPack extension type: %d",
866-
ext_type);
872+
diag_set(IllegalParams,
873+
"Unsupported MsgPack extension type: %d", ext_type);
874+
luaT_error(L);
867875
}
868876
}
869877

test/app-tap/msgpack.test.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ local function test_misc(test, s)
4848
test:is_deeply(result, {1}, "ibuf_decode result")
4949
test:ok(not st and e:match("null"), "null ibuf")
5050
st, e = pcall(s.decode, "\xd4\x0f\x00")
51-
test:is(e, "Unsupported MsgPack extension type: 15",
52-
"decode result for \\xd4\\x0f\\x00: " .. e)
51+
test:is(tostring(e), "Unsupported MsgPack extension type: 15",
52+
"decode result for \\xd4\\x0f\\x00: " .. e)
5353
test:ok(not st, "unsupported extension decode")
5454
st, e = pcall(s.decode, "\xd4\xfe\x00")
55-
test:is(e, "Unsupported MsgPack extension type: -2",
56-
"decode result for \\xd4\\xfe\\x00: " .. e)
55+
test:is(tostring(e), "Unsupported MsgPack extension type: -2",
56+
"decode result for \\xd4\\xfe\\x00: " .. e)
5757
test:ok(not st, "unsupported extension decode")
5858
end
5959

0 commit comments

Comments
 (0)