Skip to content

Commit

Permalink
Save error traces to tptmptrace.log
Browse files Browse the repository at this point in the history
  • Loading branch information
LBPHacker committed Sep 11, 2023
1 parent 904070a commit 9633cd2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tptmp/client/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ local config = {
-- current directory. Only relevant if the null manager is active.
null_manager_path = "tptmpsettings.txt",

-- * Path to error trace file relative to current directory.
trace_path = "tptmptrace.log",


-- ***********************************************************************
-- *** The following options should only be changed if you know what ***
Expand Down
24 changes: 22 additions & 2 deletions tptmp/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ local function run()
print(text)
end

local last_trace_str

local should_reconnect_at
local cli
local prof = profile.new({
Expand Down Expand Up @@ -174,6 +176,7 @@ local function run()
params.should_not_reconnect_func = function()
should_reconnect = false
end
last_trace_str = nil
cli = client.new(params)
return cli
end,
Expand Down Expand Up @@ -215,9 +218,26 @@ local function run()
end
end

local function handle_error()
local function handle_error(err)
if not last_trace_str then
local handle = io.open(config.trace_path, "wb")
handle:write(("TPTMP %s %s\n"):format(config.versionstr, os.date("%FT%TZ")))
handle:close()
win:backlog_push_error("An error occurred and its trace has been saved to " .. config.trace_path .. "; please find this file in your data folder and attach it when reporting this to developers")
win:backlog_push_error("Top-level error: " .. tostring(err))
end
local str = tostring(err) .. "\n" .. debug.traceback() .. "\n"
if last_trace_str ~= str then
last_trace_str = str
local handle = io.open(config.trace_path, "ab")
handle:write(str)
handle:close()
end
should_reconnect = false
kill_client()
if cli then
cli:stop("error handled")
kill_client()
end
end

local pcur_r, pcur_g, pcur_b, pcur_a = unpack(colours.common.player_cursor)
Expand Down

0 comments on commit 9633cd2

Please sign in to comment.