83 lines
3.6 KiB
Lua
83 lines
3.6 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Octo Error Log (Claude lane, 2026-11-22): diagnostics only.
|
|
-- Reads the native error frame's store (ScriptErrorsFrame:GetErrorData) and copies each distinct error with its
|
|
-- stack into OctoErrorLogDB, which the client writes at logout. Nothing is replaced; secret values are skipped.
|
|
-- 2026-11-28: the session is kept locally and attached to OctoErrorLogDB on this addon's ADDON_LOADED. The file runs
|
|
-- before the client loads saved variables, so a session put into the table at file load was replaced by the saved one
|
|
-- and never written (no session recorded since 11-22).
|
|
local MAX_SESSIONS, MAX_ERRORS = 5, 300
|
|
local session, seen
|
|
|
|
local function accessible(value) return not canaccessvalue or canaccessvalue(value) end
|
|
|
|
local attached
|
|
|
|
local function Attach()
|
|
if attached or not session then return end
|
|
attached = true
|
|
if type(OctoErrorLogDB) ~= "table" then OctoErrorLogDB = {} end
|
|
local db = OctoErrorLogDB
|
|
db.sessions = db.sessions or {}
|
|
table.insert(db.sessions, session)
|
|
while #db.sessions > MAX_SESSIONS do table.remove(db.sessions, 1) end
|
|
end
|
|
|
|
local function Start()
|
|
if session then return end
|
|
session = {started = date("%Y-%m-%d %H:%M:%S"), build = select(2, GetBuildInfo()), errors = {}}
|
|
seen = {}
|
|
end
|
|
|
|
local function Record(_, messageType, message, stack)
|
|
Start()
|
|
if not accessible(message) or not accessible(stack) then return end
|
|
message, stack = tostring(message or "?"), tostring(stack or "")
|
|
local key = message .. "\n" .. stack
|
|
local entry = seen[key]
|
|
if entry then entry.count = entry.count + 1; entry.last = date("%H:%M:%S"); return end
|
|
if #session.errors >= MAX_ERRORS then return end
|
|
entry = {time = date("%H:%M:%S"), type = messageType, message = message:sub(1, 2000), stack = stack:sub(1, 3000), count = 1}
|
|
seen[key] = entry
|
|
table.insert(session.errors, entry)
|
|
end
|
|
|
|
-- 2026-11-30 (Gitea #1, eineath): no hook on ScriptErrorsFrame any more. hooksecurefunc(ScriptErrorsFrame,
|
|
-- "AddErrorData") tainted the error window's own call path (gamepad SetPreferredGamepadInteractTarget popups,
|
|
-- 'attempt to call a nil value' at Blizzard_ScriptErrorsFrame.lua:121). An unparented frame now reads the window's
|
|
-- stored errors (GetCount/GetErrorData) once a second and at logout; repeats are counted from errorData.count.
|
|
local copied = {} -- error window index -> occurrences already recorded
|
|
|
|
local function Copy()
|
|
if not ScriptErrorsFrame or type(ScriptErrorsFrame.GetCount) ~= "function"
|
|
or type(ScriptErrorsFrame.GetErrorData) ~= "function" then return end
|
|
Start()
|
|
for index = 1, ScriptErrorsFrame:GetCount() or 0 do
|
|
local data = ScriptErrorsFrame:GetErrorData(index)
|
|
if type(data) == "table" then
|
|
while (copied[index] or 0) < (data.count or 1) do
|
|
copied[index] = (copied[index] or 0) + 1
|
|
pcall(Record, nil, data.messageType, data.message, data.stack)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
Start()
|
|
|
|
local watcher, waited = CreateFrame("Frame"), 0
|
|
watcher:RegisterEvent("PLAYER_LOGOUT")
|
|
watcher:SetScript("OnEvent", Copy)
|
|
watcher:SetScript("OnUpdate", function(_, elapsed)
|
|
waited = waited + elapsed
|
|
if waited >= 1 then waited = 0; Copy() end
|
|
end)
|
|
|
|
local f = CreateFrame("Frame")
|
|
f:RegisterEvent("ADDON_LOADED")
|
|
f:RegisterEvent("PLAYER_LOGIN")
|
|
f:SetScript("OnEvent", function(self, event, name)
|
|
if (event == "ADDON_LOADED" and name == "OctoErrorLog") or event == "PLAYER_LOGIN" then Start(); Attach() end
|
|
if attached then self:UnregisterAllEvents() end
|
|
end)
|