From 90dca8a51be79ea3b8704afafb2cd75b2d65e31f Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 15 May 2018 12:44:46 +0100 Subject: [PATCH] [Feature] Be more error-prone in squeezed rules --- lualib/lua_squeeze_rules.lua | 68 ++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/lualib/lua_squeeze_rules.lua b/lualib/lua_squeeze_rules.lua index 4309e1f97..a6e420fbd 100644 --- a/lualib/lua_squeeze_rules.lua +++ b/lualib/lua_squeeze_rules.lua @@ -32,51 +32,59 @@ local function gen_lua_squeeze_function(order) local symbols_disabled = task:cache_get('squeezed_disable') for _,data in ipairs(squeezed_rules[order]) do if not symbols_disabled or not symbols_disabled[data[2]] then - local ret = {data[1](task)} - - if #ret ~= 0 then - local first = ret[1] - local sym = data[2] - -- Function has returned something, so it is rule, not a plugin - if type(first) == 'boolean' then - if first then - table.remove(ret, 1) + local function real_call() + return {data[1](task)} + end - local second = ret[1] + local status, ret = pcall(real_call) - if type(second) == 'number' then + if not status then + logger.errx(task, 'error in squeezed rule %s: %s', data[2], ret) + else + if #ret ~= 0 then + local first = ret[1] + local sym = data[2] + -- Function has returned something, so it is rule, not a plugin + if type(first) == 'boolean' then + if first then table.remove(ret, 1) - if second ~= 0 then + + local second = ret[1] + + if type(second) == 'number' then + table.remove(ret, 1) + if second ~= 0 then + if type(ret[1]) == 'table' then + task:insert_result(sym, second, ret[1]) + else + task:insert_result(sym, second, ret) + end + end + else if type(ret[1]) == 'table' then - task:insert_result(sym, second, ret[1]) + task:insert_result(sym, 1.0, ret[1]) else - task:insert_result(sym, second, ret) + task:insert_result(sym, 1.0, ret) end end - else + end + elseif type(first) == 'number' then + table.remove(ret, 1) + + if first ~= 0 then if type(ret[1]) == 'table' then - task:insert_result(sym, 1.0, ret[1]) + task:insert_result(sym, first, ret[1]) else - task:insert_result(sym, 1.0, ret) + task:insert_result(sym, first, ret) end end - end - elseif type(first) == 'number' then - table.remove(ret, 1) - - if first ~= 0 then + else if type(ret[1]) == 'table' then - task:insert_result(sym, first, ret[1]) + task:insert_result(sym, 1.0, ret[1]) else - task:insert_result(sym, first, ret) + task:insert_result(sym, 1.0, ret) end end - else - if type(ret[1]) == 'table' then - task:insert_result(sym, 1.0, ret[1]) - else - task:insert_result(sym, 1.0, ret) - end end end else -- 2.39.5