Skip to content

Commit 9633cd2

Browse files
committed
Save error traces to tptmptrace.log
1 parent 904070a commit 9633cd2

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

tptmp/client/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ local config = {
5555
-- current directory. Only relevant if the null manager is active.
5656
null_manager_path = "tptmpsettings.txt",
5757

58+
-- * Path to error trace file relative to current directory.
59+
trace_path = "tptmptrace.log",
60+
5861

5962
-- ***********************************************************************
6063
-- *** The following options should only be changed if you know what ***

tptmp/client/init.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ local function run()
100100
print(text)
101101
end
102102

103+
local last_trace_str
104+
103105
local should_reconnect_at
104106
local cli
105107
local prof = profile.new({
@@ -174,6 +176,7 @@ local function run()
174176
params.should_not_reconnect_func = function()
175177
should_reconnect = false
176178
end
179+
last_trace_str = nil
177180
cli = client.new(params)
178181
return cli
179182
end,
@@ -215,9 +218,26 @@ local function run()
215218
end
216219
end
217220

218-
local function handle_error()
221+
local function handle_error(err)
222+
if not last_trace_str then
223+
local handle = io.open(config.trace_path, "wb")
224+
handle:write(("TPTMP %s %s\n"):format(config.versionstr, os.date("%FT%TZ")))
225+
handle:close()
226+
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")
227+
win:backlog_push_error("Top-level error: " .. tostring(err))
228+
end
229+
local str = tostring(err) .. "\n" .. debug.traceback() .. "\n"
230+
if last_trace_str ~= str then
231+
last_trace_str = str
232+
local handle = io.open(config.trace_path, "ab")
233+
handle:write(str)
234+
handle:close()
235+
end
219236
should_reconnect = false
220-
kill_client()
237+
if cli then
238+
cli:stop("error handled")
239+
kill_client()
240+
end
221241
end
222242

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

0 commit comments

Comments
 (0)