Skip to content

Commit

Permalink
console: raise error if lua_encode failed
Browse files Browse the repository at this point in the history
lua_encode can raise an exception (e.g. from luaL_checkfield) or return
`nil, err` result. Handle it in lbox_console_format_lua, similar to
lbox_console_format_yaml.

When fixed, it will expose another issue - nil value can not be
serialized:

```
tarantool> \set output lua
true;
tarantool> 1, nil, 2
1, {error = "console: exception while formatting the output:
    \"serializer: unexpected data (nd.field.size 0 nd.field.type 5)\""}, 2;
tarantool>
```

Fix this too.

Part of tarantool#6781
Part of tarantool#6934

NO_DOC=bugfix
NO_TEST=not a visible change
NO_CHANGELOG=not a visible change
  • Loading branch information
Gumix authored and mkokryashkin committed Sep 9, 2022
1 parent e5407da commit fe72e7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/box/lua/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ lbox_console_format_lua(struct lua_State *L)

lua_replace(L, 1);
lua_settop(L, 1);
return lua_encode(L, serializer_lua, &opts);
int ret = lua_encode(L, serializer_lua, &opts);
if (ret == 2) {
/*
* Nil and error object are pushed onto the stack.
*/
assert(lua_isnil(L, -2));
assert(lua_isstring(L, -1));
return luaL_error(L, lua_tostring(L, -1));
}
assert(ret == 1);
return ret;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/box/lua/serialize_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ dump_root(struct lua_dumper *d)

luaL_checkfield(d->L, d->cfg, lua_gettop(d->L), &nd.field);

if (nd.field.type != MP_ARRAY || nd.field.size != 1) {
if (nd.field.type != MP_ARRAY || nd.field.size > 1) {
d->err = EINVAL;
snprintf(d->err_msg, sizeof(d->err_msg),
"serializer: unexpected data "
Expand Down

0 comments on commit fe72e7e

Please sign in to comment.