From 748dbc50144f6b973159e4150a8628e23442fc8d Mon Sep 17 00:00:00 2001 From: littensy <56808540+littensy@users.noreply.github.com> Date: Thu, 2 Apr 2026 05:17:51 -0700 Subject: [PATCH] refactor: error for effect cleanup errors --- packages/charm/src/init.luau | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/charm/src/init.luau b/packages/charm/src/init.luau index 46be53c..b226dd2 100644 --- a/packages/charm/src/init.luau +++ b/packages/charm/src/init.luau @@ -178,6 +178,9 @@ end @param cleanups List of cleanup functions ]] local function runCleanups(cleanups: { Cleanup }) + local hasErrors = false + local errors = {} + for index, cleanup in cleanups do cleanups[index] = nil @@ -186,9 +189,14 @@ local function runCleanups(cleanups: { Cleanup }) activeSub = prevSub if not success then - warn("Error occurred during effect cleanup:", result) + hasErrors = true + table.insert(errors, tostring(result)) end end + + if hasErrors then + error(`Errors occurred during effect cleanup:\n\n${table.concat(errors, "\n\n")}`, 0) + end end --[[ @@ -404,14 +412,14 @@ local function notify(effect: ReactiveNode) queuedLength = insertIndex -- Reverse the collected effects to ensure outer effects run first - while true do + repeat insertIndex -= 1 if firstInsertedIndex >= insertIndex then break end queued[firstInsertedIndex], queued[insertIndex] = queued[insertIndex], queued[firstInsertedIndex] firstInsertedIndex += 1 - end + until false end --[[