From 1a1bda6b4b37a21f3f398e02e760cd50b0e034ef Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 10 Aug 2020 14:27:39 +0200 Subject: [PATCH] remove error handling --- builtin/abm_calls.lua | 4 +-- builtin/globalstep.lua | 7 +---- builtin/lbm_calls.lua | 4 +-- builtin/nodetimer_calls.lua | 5 +--- chatcommands.lua | 52 ------------------------------------- init.lua | 4 +-- protected_call.lua | 27 ------------------- 7 files changed, 5 insertions(+), 98 deletions(-) delete mode 100644 protected_call.lua diff --git a/builtin/abm_calls.lua b/builtin/abm_calls.lua index d162fe0..ff7189f 100644 --- a/builtin/abm_calls.lua +++ b/builtin/abm_calls.lua @@ -21,9 +21,7 @@ minetest.register_on_mods_loaded(function() metric.inc() local t0 = minetest.get_us_time() - monitoring.protected_call(metric, function() - old_action(pos, node, active_object_count, active_object_count_wider) - end, pos) + old_action(pos, node, active_object_count, active_object_count_wider) local t1 = minetest.get_us_time() local diff = t1 - t0 metric_time.inc(diff) diff --git a/builtin/globalstep.lua b/builtin/globalstep.lua index 7d544ee..56f03ac 100644 --- a/builtin/globalstep.lua +++ b/builtin/globalstep.lua @@ -16,7 +16,6 @@ minetest.register_on_mods_loaded(function() for i, globalstep in ipairs(minetest.registered_globalsteps) do local info = minetest.callback_origins[globalstep] - local error_state = {} local new_callback = function(dtime) @@ -26,11 +25,7 @@ minetest.register_on_mods_loaded(function() metric.inc() local t0 = minetest.get_us_time() - - monitoring.protected_call(error_state, function() - globalstep(dtime) - end) - + globalstep(dtime) local t1 = minetest.get_us_time() local diff = t1 - t0 metric_time.inc(diff) diff --git a/builtin/lbm_calls.lua b/builtin/lbm_calls.lua index e5219fd..1355bf4 100644 --- a/builtin/lbm_calls.lua +++ b/builtin/lbm_calls.lua @@ -21,9 +21,7 @@ minetest.register_on_mods_loaded(function() metric.inc() local t0 = minetest.get_us_time() - monitoring.protected_call(metric, function() - old_action(pos, node) - end, pos) + old_action(pos, node) local t1 = minetest.get_us_time() local diff = t1 - t0 metric_time.inc(diff) diff --git a/builtin/nodetimer_calls.lua b/builtin/nodetimer_calls.lua index 5f16c68..eecce6e 100644 --- a/builtin/nodetimer_calls.lua +++ b/builtin/nodetimer_calls.lua @@ -23,10 +23,7 @@ minetest.register_on_mods_loaded(function() metric.inc() local t0 = minetest.get_us_time() - local result - monitoring.protected_call(metric, function() - result = old_action(pos, elapsed) - end, pos) + local result = old_action(pos, elapsed) local t1 = minetest.get_us_time() local diff = t1 - t0 diff --git a/chatcommands.lua b/chatcommands.lua index afe89c8..d7bf082 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -15,55 +15,3 @@ minetest.register_chatcommand("metric", { return true, "" .. metric.value or "" end }) - - - -minetest.register_chatcommand("get_errors", { - description = "shows all catched errors", - func = function() - if not monitoring.settings.handle_errors then - return false, "Error-handling not enabled!" - end - - local res = "List of handled errors: \n" - local count = 0 - - for _, metric in ipairs(monitoring.metrics) do - local pos_msg = "" - if metric.error_pos then - pos_msg = " at position " .. minetest.pos_to_string(metric.error_pos) - end - - if metric.error then - count = count + 1 - res = res .. metric.name .. ": " .. metric.error .. pos_msg .. "\n" - end - end - - if count > 0 then - return true, res - else - return true, "No errors to report" - end - end -}) - - -minetest.register_chatcommand("reset_errors", { - description = "resets all catched errors", - func = function() - if not monitoring.settings.handle_errors then - return false, "Error-handling not enabled!" - end - - for _, metric in ipairs(monitoring.metrics) do - if metric.error then - metric.error = false - end - end - - monitoring.error_count_metric.set(0) - - return true, "Error state reset" - end -}) diff --git a/init.lua b/init.lua index 30520cd..d4a0999 100644 --- a/init.lua +++ b/init.lua @@ -11,8 +11,7 @@ monitoring = { builtin_disable = minetest.settings:get_bool("monitoring.builtin_disable"), csv_enable = minetest.settings:get_bool("monitoring.csv_enable"), json_enable = minetest.settings:get_bool("monitoring.json_enable"), - debug = minetest.settings:get_bool("monitoring.debug"), - handle_errors = minetest.settings:get_bool("monitoring.handle_errors") + debug = minetest.settings:get_bool("monitoring.debug") } } @@ -23,7 +22,6 @@ dofile(MP.."/metrictypes/gauge.lua") dofile(MP.."/metrictypes/counter.lua") dofile(MP.."/metrictypes/histogram.lua") -dofile(MP.."/protected_call.lua") dofile(MP.."/chatcommands.lua") dofile(MP.."/register.lua") dofile(MP.."/sampling.lua") diff --git a/protected_call.lua b/protected_call.lua deleted file mode 100644 index 8b105bb..0000000 --- a/protected_call.lua +++ /dev/null @@ -1,27 +0,0 @@ - -monitoring.error_count_metric = monitoring.counter("error_count", "number of catched errors") - --- state can be a metric or empty object {} -function monitoring.protected_call(state, fn, pos) - if not monitoring.settings.handle_errors then - -- don't handle anything here - return fn() - end - - -- handle errors with pcall and avoid further execution of failed functions - - if state.error then - -- metric errored previously, don't execute again - return - end - - local success, message = pcall(fn) - - if not success then - -- execution failed, mark as in error - minetest.log("error", "[monitoring] catched error: " .. (message or "")) - state.error = message - state.error_pos = pos - monitoring.error_count_metric.inc() - end -end