mirror of
https://github.com/GreenComfyTea/MHR-Overlay.git
synced 2026-01-25 04:48:22 -08:00
Implement Error Handler
This commit is contained in:
@@ -2,6 +2,7 @@ local this = {};
|
||||
|
||||
local utils;
|
||||
local language;
|
||||
local error_handler;
|
||||
|
||||
local sdk = sdk;
|
||||
local tostring = tostring;
|
||||
@@ -7564,6 +7565,10 @@ function this.init_default()
|
||||
outline = 0xC0000000
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
debug = {
|
||||
history_size = 64
|
||||
}
|
||||
};
|
||||
end
|
||||
@@ -7572,7 +7577,7 @@ function this.load_current_config_value()
|
||||
local loaded_config = json.load_file(this.current_config_value_file_name);
|
||||
if loaded_config ~= nil then
|
||||
if loaded_config.config == nil then
|
||||
log.info("[MHR Overlay] old config.json loaded successfully");
|
||||
log.info("[MHR Overlay] Old config.json Loaded Successfully");
|
||||
|
||||
local config_save = {
|
||||
config = this.current_config_name
|
||||
@@ -7590,11 +7595,12 @@ function this.load_current_config_value()
|
||||
|
||||
is_old_config_transferred = true;
|
||||
else
|
||||
log.info("[MHR Overlay] config.json loaded successfully");
|
||||
log.info("[MHR Overlay] config.json Loaded Successfully");
|
||||
this.current_config_name = loaded_config.config;
|
||||
end
|
||||
else
|
||||
log.error("[MHR Overlay] Failed to load config.json");
|
||||
log.error("[MHR Overlay] Failed to Load config.json");
|
||||
error_handler.report("config.load_current_config_value", "Failed to Load config.json");
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7615,8 +7621,7 @@ function this.load_configs()
|
||||
|
||||
local loaded_config = json.load_file(config_file_name);
|
||||
if loaded_config ~= nil then
|
||||
log.info("[MHR Overlay] " .. config_name .. ".json loaded successfully");
|
||||
|
||||
log.info(string.format("[MHR Overlay] %s.json Loaded Successfully", config_name));
|
||||
|
||||
local merged_config = utils.table.merge(this.default_config, loaded_config);
|
||||
merged_config.version = this.version;
|
||||
@@ -7630,7 +7635,8 @@ function this.load_configs()
|
||||
this.current_config = merged_config;
|
||||
end
|
||||
else
|
||||
log.error("[MHR Overlay] Failed to load " .. config_name .. ".json");
|
||||
log.error(string.format("[MHR Overlay] Failed to Load %s.json", config_name));
|
||||
error_handler.report("config.load_configs", string.format("Failed to Load %s.json", config_name));
|
||||
end
|
||||
|
||||
::continue::
|
||||
@@ -7664,7 +7670,8 @@ function this.save(file_name, config_table)
|
||||
if success then
|
||||
log.info("[MHR Overlay] " .. file_name .. " saved successfully");
|
||||
else
|
||||
log.error("[MHR Overlay] Failed to save " .. file_name);
|
||||
error_handler.report("config.load_configs", string.format("Failed to Save %s", file_name));
|
||||
log.error(string.format("[MHR Overlay] Failed to Save %s", file_name));
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7719,6 +7726,7 @@ end
|
||||
function this.init_dependencies()
|
||||
utils = require("MHR_Overlay.Misc.utils");
|
||||
language = require("MHR_Overlay.Misc.language");
|
||||
error_handler = require("MHR_Overlay.Misc.error_handler");
|
||||
end
|
||||
|
||||
function this.init_module()
|
||||
|
||||
88
reframework/autorun/MHR_Overlay/Misc/error_handler.lua
Normal file
88
reframework/autorun/MHR_Overlay/Misc/error_handler.lua
Normal file
@@ -0,0 +1,88 @@
|
||||
local this = {};
|
||||
|
||||
local time;
|
||||
local utils;
|
||||
local config;
|
||||
|
||||
local sdk = sdk;
|
||||
local tostring = tostring;
|
||||
local pairs = pairs;
|
||||
local ipairs = ipairs;
|
||||
local tonumber = tonumber;
|
||||
local require = require;
|
||||
local pcall = pcall;
|
||||
local table = table;
|
||||
local string = string;
|
||||
local Vector3f = Vector3f;
|
||||
local d2d = d2d;
|
||||
local math = math;
|
||||
local json = json;
|
||||
local log = log;
|
||||
local fs = fs;
|
||||
local next = next;
|
||||
local type = type;
|
||||
local setmetatable = setmetatable;
|
||||
local getmetatable = getmetatable;
|
||||
local assert = assert;
|
||||
local select = select;
|
||||
local coroutine = coroutine;
|
||||
local utf8 = utf8;
|
||||
local re = re;
|
||||
local imgui = imgui;
|
||||
local draw = draw;
|
||||
local Vector2f = Vector2f;
|
||||
local reframework = reframework;
|
||||
local os = os;
|
||||
local ValueType = ValueType;
|
||||
local package = package;
|
||||
|
||||
this.list = {};
|
||||
this.is_empty = true;
|
||||
|
||||
this.history = {};
|
||||
|
||||
function this.report(error_key, error_message)
|
||||
if error_key == nil or error_key == ""
|
||||
or error_message == nil or error_message == "" then
|
||||
return;
|
||||
end
|
||||
|
||||
local error_time = time.total_elapsed_script_seconds;
|
||||
|
||||
local error = {
|
||||
key = error_key,
|
||||
time = error_time,
|
||||
message = error_message
|
||||
};
|
||||
|
||||
this.list[error_key] = error;
|
||||
this.is_empty = false;
|
||||
|
||||
this.add_to_history(error_key, error);
|
||||
end
|
||||
|
||||
function this.add_to_history(error_key, error)
|
||||
this.clear_history();
|
||||
|
||||
table.insert(this.history, error);
|
||||
end
|
||||
|
||||
function this.clear_history()
|
||||
local history_size = config.current_config.debug.history_size;
|
||||
|
||||
while #this.history >= history_size do
|
||||
table.remove(this.history, 1);
|
||||
end
|
||||
end
|
||||
|
||||
function this.init_dependencies()
|
||||
time = require("MHR_Overlay.Game_Handler.time");
|
||||
utils = require("MHR_Overlay.Misc.utils");
|
||||
config = require("MHR_Overlay.Misc.config");
|
||||
end
|
||||
|
||||
function this.init_module()
|
||||
|
||||
end
|
||||
|
||||
return this;
|
||||
@@ -1,6 +1,7 @@
|
||||
local this = {};
|
||||
|
||||
local utils;
|
||||
local error_handler;
|
||||
|
||||
local sdk = sdk;
|
||||
local tostring = tostring;
|
||||
@@ -607,7 +608,12 @@ this.default_language = {
|
||||
top_to_bottom = "Top to Bottom",
|
||||
bottom_to_top = "Bottom to Top",
|
||||
|
||||
right_alignment_shift = "Right Alignment Shift"
|
||||
right_alignment_shift = "Right Alignment Shift",
|
||||
|
||||
debug = "Debug",
|
||||
everything_seems_to_be_ok = "Everything seems to be OK!",
|
||||
error_history = "Error History",
|
||||
history_size = "History Size"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -626,18 +632,17 @@ function this.load()
|
||||
|
||||
local loaded_language = json.load_file(language_file_name);
|
||||
if loaded_language ~= nil then
|
||||
log.info(string.format("[MHR Overlay] %s.json Loaded Successfully", language_file_name));
|
||||
|
||||
log.info("[MHR Overlay] " .. language_file_name .. ".json loaded successfully");
|
||||
table.insert(this.language_names, language_name);
|
||||
|
||||
local merged_language = utils.table.merge(this.default_language, loaded_language);
|
||||
table.insert(this.languages, merged_language);
|
||||
|
||||
this.save(language_file_name, merged_language);
|
||||
|
||||
|
||||
else
|
||||
log.error("[MHR Overlay] Failed to load " .. language_file_name .. ".json");
|
||||
error_handler.report("language.load", string.format("Failed to load %s.json", language_file_name));
|
||||
log.error(string.format("[MHR Overlay] Failed to Load %s.json", language_file_name));
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -645,9 +650,10 @@ end
|
||||
function this.save(file_name, language_table)
|
||||
local success = json.dump_file(file_name, language_table);
|
||||
if success then
|
||||
log.info("[MHR Overlay] " .. file_name .. " saved successfully");
|
||||
log.info(string.format("[MHR Overlay] %s Saved Successfully", file_name));
|
||||
else
|
||||
log.error("[MHR Overlay] Failed to save " .. file_name);
|
||||
error_handler.report("language.save", string.format("[MHR Overlay] Failed to Save %s", file_name));
|
||||
log.error(string.format("[MHR Overlay] Failed to Save %s", file_name));
|
||||
end
|
||||
end
|
||||
|
||||
@@ -661,6 +667,7 @@ end
|
||||
|
||||
function this.init_dependencies()
|
||||
utils = require("MHR_Overlay.Misc.utils");
|
||||
error_handler = require("MHR_Overlay.Misc.error_handler");
|
||||
end
|
||||
|
||||
function this.init_module()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local this = {};
|
||||
|
||||
local language;
|
||||
local error_handler;
|
||||
|
||||
local sdk = sdk;
|
||||
local tostring = tostring;
|
||||
@@ -956,6 +957,7 @@ end
|
||||
|
||||
function this.init_dependencies()
|
||||
language = require("MHR_Overlay.Misc.language");
|
||||
error_handler = require("MHR_Overlay.Misc.error_handler");
|
||||
end
|
||||
|
||||
function this.init_module()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
local this = {};
|
||||
|
||||
local error_handler;
|
||||
|
||||
local sdk = sdk;
|
||||
local tostring = tostring;
|
||||
local pairs = pairs;
|
||||
@@ -414,6 +416,7 @@ function this.unicode.sub(str, i, j)
|
||||
end
|
||||
|
||||
function this.init_dependencies()
|
||||
error_handler = require("MHR_Overlay.Misc.error_handler");
|
||||
end
|
||||
|
||||
function this.init_module()
|
||||
|
||||
Reference in New Issue
Block a user