From 2b387d1c853077fff036d3360ccea2f14f574bdc Mon Sep 17 00:00:00 2001 From: Roman Khabibov <roman.habibov@tarantool.org> Date: Mon, 25 Mar 2019 20:52:05 +0300 Subject: [PATCH] tarantoolctl: raise error when box.cfg isn't called Added a check whether box.cfg() is called within an instance file. If box.cfg() is missed, point a user the reason of a fail explicitly. Before this commit the error was look so: /usr/bin/tarantoolctl:541: attempt to index a nil value Closes #3953 --- extra/dist/tarantoolctl.in | 9 +++++++-- test/app-tap/tarantoolctl.test.lua | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 0796f46053..7228b78ad2 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -547,8 +547,13 @@ local function start() end os.exit(1) end - local old_call = getmetatable(box.cfg).__call - getmetatable(box.cfg).__call = function(old_cfg, cfg) + local box_cfg_mt = getmetatable(box.cfg) + if box_cfg_mt == nil then + log.error('box.cfg() is not called in an instance file') + os.exit(1) + end + local old_call = box_cfg_mt.__call + box_cfg_mt.__call = function(old_cfg, cfg) if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then cfg.pid_file = old_cfg.pid_file end diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 62a78d6bf3..c1e1490ca1 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -178,12 +178,14 @@ test:plan(8) -- must be stopped afterwards do local dir = fio.tempdir() - local code = [[ box.cfg{memtx_memory = 104857600} ]] - create_script(dir, 'script.lua', code) + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) local status, err = pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", + "box.cfg() is not called in an instance file") check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") tctl_wait_start(dir, 'script') check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") -- GitLab