From b18592f35820259cc3d9832fcef3cb031de3a0cf Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Sat, 6 Dec 2025 10:43:43 -0500 Subject: [PATCH] move old systemout to use errorhandler --- modules/Animation.lua | 70 +++++++++++++++++++++++++++++++++++---- modules/Element.lua | 30 +++++++++++++---- modules/MemoryScanner.lua | 22 ++++++++++-- modules/Performance.lua | 18 +++++----- modules/StateManager.lua | 2 -- modules/utils.lua | 36 +++++++++++++++++--- 6 files changed, 147 insertions(+), 31 deletions(-) diff --git a/modules/Animation.lua b/modules/Animation.lua index 2cfdac6..21bbbc6 100644 --- a/modules/Animation.lua +++ b/modules/Animation.lua @@ -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 diff --git a/modules/Element.lua b/modules/Element.lua index 7e8d5ba..3f0a8e9 100644 --- a/modules/Element.lua +++ b/modules/Element.lua @@ -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 diff --git a/modules/MemoryScanner.lua b/modules/MemoryScanner.lua index ae76e36..853b59b 100644 --- a/modules/MemoryScanner.lua +++ b/modules/MemoryScanner.lua @@ -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 diff --git a/modules/Performance.lua b/modules/Performance.lua index 322e92e..ef7281c 100644 --- a/modules/Performance.lua +++ b/modules/Performance.lua @@ -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 diff --git a/modules/StateManager.lua b/modules/StateManager.lua index de47e7f..a0dee6a 100644 --- a/modules/StateManager.lua +++ b/modules/StateManager.lua @@ -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 diff --git a/modules/utils.lua b/modules/utils.lua index 7108ae4..17ec0aa 100644 --- a/modules/utils.lua +++ b/modules/utils.lua @@ -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