Skip to content
Snippets Groups Projects
Commit 69852e1f authored by Ilya Verbin's avatar Ilya Verbin Committed by Vladimir Davydov
Browse files

console: raise error if lua_encode failed

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 #6781
Part of #6934

NO_DOC=bugfix
NO_TEST=not a visible change
NO_CHANGELOG=not a visible change
parent 405bfe40
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
/*
......
......@@ -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 "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment