move old systemout to use errorhandler

This commit is contained in:
Michael Freno
2025-12-06 10:43:43 -05:00
parent c7b242a1c8
commit b18592f358
6 changed files with 147 additions and 31 deletions

View File

@@ -629,7 +629,15 @@ function Animation:update(dt, element)
if self.onStart and type(self.onStart) == "function" then
local success, err = pcall(self.onStart, self, element)
if not success then
print(string.format("[Animation] onStart error: %s", tostring(err)))
-- Use ErrorHandler if available via Animation module
if Animation._ErrorHandler then
Animation._ErrorHandler:warn("Animation", "EVT_002", {
callback = "onStart",
error = tostring(err),
})
else
print(string.format("[Animation] onStart error: %s", tostring(err)))
end
end
end
end
@@ -645,7 +653,15 @@ function Animation:update(dt, element)
if self.onComplete and type(self.onComplete) == "function" then
local success, err = pcall(self.onComplete, self, element)
if not success then
print(string.format("[Animation] onComplete error: %s", tostring(err)))
-- Use ErrorHandler if available via Animation module
if Animation._ErrorHandler then
Animation._ErrorHandler:warn("Animation", "EVT_002", {
callback = "onComplete",
error = tostring(err),
})
else
print(string.format("[Animation] onComplete error: %s", tostring(err)))
end
end
end
return true
@@ -678,7 +694,15 @@ function Animation:update(dt, element)
if self.onComplete and type(self.onComplete) == "function" then
local success, err = pcall(self.onComplete, self, element)
if not success then
print(string.format("[Animation] onComplete error: %s", tostring(err)))
-- Use ErrorHandler if available via Animation module
if Animation._ErrorHandler then
Animation._ErrorHandler:warn("Animation", "EVT_002", {
callback = "onComplete",
error = tostring(err),
})
else
print(string.format("[Animation] onComplete error: %s", tostring(err)))
end
end
end
return true
@@ -691,7 +715,15 @@ function Animation:update(dt, element)
local progress = self.elapsed / self.duration
local success, err = pcall(self.onUpdate, self, element, progress)
if not success then
print(string.format("[Animation] onUpdate error: %s", tostring(err)))
-- Use ErrorHandler if available via Animation module
if Animation._ErrorHandler then
Animation._ErrorHandler:warn("Animation", "EVT_002", {
callback = "onUpdate",
error = tostring(err),
})
else
print(string.format("[Animation] onUpdate error: %s", tostring(err)))
end
end
end
@@ -1002,7 +1034,15 @@ function Animation:cancel(element)
if self.onCancel and type(self.onCancel) == "function" then
local success, err = pcall(self.onCancel, self, element)
if not success then
print(string.format("[Animation] onCancel error: %s", tostring(err)))
-- Use ErrorHandler if available via Animation module
if Animation._ErrorHandler then
Animation._ErrorHandler:warn("Animation", "EVT_002", {
callback = "onCancel",
error = tostring(err),
})
else
print(string.format("[Animation] onCancel error: %s", tostring(err)))
end
end
end
end
@@ -1369,7 +1409,15 @@ function AnimationGroup:update(dt, element)
if self.onStart and type(self.onStart) == "function" then
local success, err = pcall(self.onStart, self)
if not success then
print(string.format("[AnimationGroup] onStart error: %s", tostring(err)))
-- Use ErrorHandler if available via AnimationGroup module
if AnimationGroup._ErrorHandler then
AnimationGroup._ErrorHandler:warn("AnimationGroup", "EVT_002", {
callback = "onStart",
error = tostring(err),
})
else
print(string.format("[AnimationGroup] onStart error: %s", tostring(err)))
end
end
end
end
@@ -1389,7 +1437,15 @@ function AnimationGroup:update(dt, element)
if self.onComplete and type(self.onComplete) == "function" then
local success, err = pcall(self.onComplete, self)
if not success then
print(string.format("[AnimationGroup] onComplete error: %s", tostring(err)))
-- Use ErrorHandler if available via AnimationGroup module
if AnimationGroup._ErrorHandler then
AnimationGroup._ErrorHandler:warn("AnimationGroup", "EVT_002", {
callback = "onComplete",
error = tostring(err),
})
else
print(string.format("[AnimationGroup] onComplete error: %s", tostring(err)))
end
end
end
end

View File

@@ -559,13 +559,19 @@ function Element.new(props)
Element._Context.deferCallback(function()
local success, callbackErr = pcall(self.onImageLoad, self, loadedImage)
if not success then
print(string.format("[Element] onImageLoad error: %s", tostring(callbackErr)))
Element._ErrorHandler:warn("Element", "EVT_002", {
callback = "onImageLoad",
error = tostring(callbackErr),
})
end
end)
else
local success, callbackErr = pcall(self.onImageLoad, self, loadedImage)
if not success then
print(string.format("[Element] onImageLoad error: %s", tostring(callbackErr)))
Element._ErrorHandler:warn("Element", "EVT_002", {
callback = "onImageLoad",
error = tostring(callbackErr),
})
end
end
end
@@ -578,13 +584,19 @@ function Element.new(props)
Element._Context.deferCallback(function()
local success, callbackErr = pcall(self.onImageError, self, err or "Unknown error")
if not success then
print(string.format("[Element] onImageError error: %s", tostring(callbackErr)))
Element._ErrorHandler:warn("Element", "EVT_002", {
callback = "onImageError",
error = tostring(callbackErr),
})
end
end)
else
local success, callbackErr = pcall(self.onImageError, self, err or "Unknown error")
if not success then
print(string.format("[Element] onImageError error: %s", tostring(callbackErr)))
Element._ErrorHandler:warn("Element", "EVT_002", {
callback = "onImageError",
error = tostring(callbackErr),
})
end
end
end
@@ -597,13 +609,19 @@ function Element.new(props)
Element._Context.deferCallback(function()
local success, callbackErr = pcall(self.onImageLoad, self, self.image)
if not success then
print(string.format("[Element] onImageLoad error: %s", tostring(callbackErr)))
Element._ErrorHandler:warn("Element", "EVT_002", {
callback = "onImageLoad",
error = tostring(callbackErr),
})
end
end)
else
local success, callbackErr = pcall(self.onImageLoad, self, self.image)
if not success then
print(string.format("[Element] onImageLoad error: %s", tostring(callbackErr)))
Element._ErrorHandler:warn("Element", "EVT_002", {
callback = "onImageLoad",
error = tostring(callbackErr),
})
end
end
end

View File

@@ -659,9 +659,27 @@ function MemoryScanner.saveReport(report, filename)
if file then
file:write(formatted)
file:close()
print(string.format("[MemoryScanner] Report saved to %s", filename))
-- Use ErrorHandler if available, otherwise fall back to print
if MemoryScanner._ErrorHandler then
MemoryScanner._ErrorHandler:warn("MemoryScanner", "RES_004", {
resourceType = "report",
path = filename,
status = "saved",
})
else
print(string.format("[MemoryScanner] Report saved to %s", filename))
end
else
print(string.format("[MemoryScanner] Failed to save report to %s", filename))
-- Use ErrorHandler if available, otherwise fall back to print
if MemoryScanner._ErrorHandler then
MemoryScanner._ErrorHandler:warn("MemoryScanner", "RES_004", {
resourceType = "report",
path = filename,
status = "failed to save",
})
else
print(string.format("[MemoryScanner] Failed to save report to %s", filename))
end
end
end

View File

@@ -145,7 +145,15 @@ function Performance:stopTimer(name)
end
if self.logToConsole then
print(string.format("[Performance] %s: %.3fms", name, elapsed))
-- Use ErrorHandler if available, otherwise fall back to print
if self._ErrorHandler and self._ErrorHandler.warn then
self._ErrorHandler:warn("Performance", "PERF_001", {
metric = name,
elapsed = string.format("%.3fms", elapsed),
})
else
print(string.format("[Performance] %s: %.3fms", name, elapsed))
end
end
return elapsed
@@ -284,9 +292,6 @@ function Performance:_addWarning(name, value, level)
value = string.format("%.2fms", value),
threshold = level == "critical" and self.criticalThresholdMs or self.warningThresholdMs,
})
else
local prefix = level == "critical" and "[CRITICAL]" or "[WARNING]"
print(string.format("%s Performance: %s = %.2fms", prefix, name, value))
end
self._shownWarnings[warningKey] = now
@@ -409,11 +414,6 @@ function Performance:logWarning(warningKey, module, message, details, suggestion
if self._ErrorHandler and self._ErrorHandler.warn then
self._ErrorHandler:warn(module, "PERF_001", details or {})
else
print(string.format("[FlexLove - %s] Performance Warning: %s", module, message))
if suggestion then
print(string.format(" Suggestion: %s", suggestion))
end
end
end

View File

@@ -538,8 +538,6 @@ function StateManager.getStats()
expected = "near 0",
frameNumber = frameNumber,
})
else
print(string.format("[StateManager] WARNING: callSiteCounters has %d entries", callSiteCount))
end
end

View File

@@ -224,7 +224,15 @@ function FONT_CACHE.get(size, fontPath)
if success then
font = result
else
print("[FlexLove] Failed to load font: " .. fontPath .. " - using default font")
-- Use ErrorHandler if available, otherwise fall back to print
if ErrorHandler then
ErrorHandler:warn("utils", "RES_004", {
resourceType = "font",
path = fontPath,
})
else
print("[FlexLove] Failed to load font: " .. fontPath .. " - using default font")
end
font = love.graphics.newFont(size)
end
else
@@ -462,8 +470,17 @@ local function safeLoadImage(imagePath)
end)
if not success then
local errorMsg = string.format("[FlexLove] Failed to load image data: %s - %s", imagePath, tostring(imageData))
print(errorMsg)
local errorMsg = string.format("Failed to load image data: %s - %s", imagePath, tostring(imageData))
-- Use ErrorHandler if available, otherwise fall back to print
if ErrorHandler then
ErrorHandler:warn("utils", "RES_004", {
resourceType = "image data",
path = imagePath,
error = tostring(imageData),
})
else
print("[FlexLove] " .. errorMsg)
end
return nil, nil, errorMsg
end
@@ -474,8 +491,17 @@ local function safeLoadImage(imagePath)
if imageSuccess then
return image, imageData, nil
else
local errorMsg = string.format("[FlexLove] Failed to create image: %s - %s", imagePath, tostring(image))
print(errorMsg)
local errorMsg = string.format("Failed to create image: %s - %s", imagePath, tostring(image))
-- Use ErrorHandler if available, otherwise fall back to print
if ErrorHandler then
ErrorHandler:warn("utils", "RES_004", {
resourceType = "image",
path = imagePath,
error = tostring(image),
})
else
print("[FlexLove] " .. errorMsg)
end
return nil, nil, errorMsg
end
end