Skip to content

Instantly share code, notes, and snippets.

@EngineerSmith
Created November 6, 2025 20:22
Show Gist options
  • Select an option

  • Save EngineerSmith/0b348d6c9f34406f9e21f53958e7ea8d to your computer and use it in GitHub Desktop.

Select an option

Save EngineerSmith/0b348d6c9f34406f9e21f53958e7ea8d to your computer and use it in GitHub Desktop.
Snippet of MintMouse's traceback cleanup function
local filterPatterns = {
{ -- Remove the `logger.error` instance call
pattern = "/logger/init%.lua:%d+: in function 'error'",
condition = function(lines, i)
local previousLine = lines[i-1]
return love.mintmousse._insideError and type(previousLine) == "string" and previousLine:find("%[C%]: in function 'error'")
end,
counts = 1,
},
{ -- Remove the `love.errorhandler` call
pattern = "%.lua:%d+: in function 'handler'",
condition = function(lines, i)
local insideIssue = love.mintmousse._insideFatal or love.mintmousse._insideError
local nextLine = lines[i+1]
return insideIssue and type(nextLine) == "string" and nextLine:find("%[love \"boot%.lua\"%]:%d+:")
end,
counts = 1,
},
{ -- Remove love internal `xpcall` call; works by searching the stack above for "boot.lua"
pattern = "%[C%]: in function 'xpcall'",
condition = function(lines, i)
local nextLine = lines[i+1]
local previousLine = lines[i-1]
return type(nextLine) == "string" and nextLine:find("%[love \"boot%.lua\"%]:%d+:") or
type(previousLine) == "string" and previousLine:find("%[love \"callbacks%.lua\"%]:%d+:")
end,
counts = -1, -- Find all
},
{ -- Remove love internal `require` call; works by searching the stack above for "boot.lua"
pattern = "%[C%]: in function 'require'",
condition = function(lines, i)
local nextLine = lines[i+1]
return type(nextLine) == "string" and nextLine:find("%[love \"boot%.lua\"%]:%d+:")
end,
counts = -1, -- Find all
},
{ pattern = "%[love \"boot%.lua\"%]:%d+:", counts = -1 }, -- Remove all love internal boot calls (must be after conditional)
{ pattern = "%[love \"callbacks%.lua\"%]:%d+:", counts = -1 }, -- Remove all love internal callbacks calls
}
-- Cleans up a traceback string by removing lines matching specific filters to make the issue much more visible.
love.mintmousse._cleanUpTraceback = function(traceback)
-- Used for debugging
-- GLOBAL_print("---- BEFORE ----")
-- GLOBAL_print(traceback)
-- GLOBAL_print("---- ----")
-- Ensure traceback is formatted in a usable context
if traceback:find("\n$") then
traceback = traceback .. "\n"
end
local lines = { }
for line in (traceback):gmatch("([^\n]+)\n") do
table.insert(lines, line)
end
for _, rule in ipairs(filterPatterns) do
local pattern = rule.pattern
local remaindingCounts = rule.counts
local indicesToRemove = { }
for i, line in ipairs(lines) do
if line:find(pattern) then
local conditionMet = true
if type(rule.condition) == "function" then
conditionMet = rule.condition(lines, i)
end
if conditionMet then
table.insert(indicesToRemove, i)
remaindingCounts = remaindingCounts - 1
if remaindingCounts == 0 then
break
end
end
end
end
for i = #indicesToRemove, 1, -1 do
table.remove(lines, indicesToRemove[i])
end
end
-- Reconstruct traceback string. Ensuring it ends with a newline.
traceback = table.concat(lines, "\n") .. "\n"
-- Used for debugging
-- GLOBAL_print("---- AFTER ----")
-- GLOBAL_print(traceback)
-- GLOBAL_print("---- ----")
return traceback
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment