fix: Reinitialize SnapController after clearing state#3870
fix: Reinitialize SnapController after clearing state#3870FrederikBolding merged 4 commits intomainfrom
SnapController after clearing state#3870Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3870 +/- ##
=======================================
Coverage 98.57% 98.57%
=======================================
Files 425 425
Lines 12311 12314 +3
Branches 1919 1921 +2
=======================================
+ Hits 12136 12139 +3
Misses 175 175 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| this.#controllerSetup = createDeferredPromise(); | ||
|
|
||
| // Re-initialize the controller after clearing the state, re-installing preinstalled Snaps etc. | ||
| await this.init(false); |
There was a problem hiding this comment.
clearState silently swallows errors, breaking controller permanently
Medium Severity
clearState delegates to init(false), but init's try/catch catches all errors (including from #handlePreinstalledSnaps) and only calls logWarning without rethrowing. Previously, clearState called #handlePreinstalledSnaps directly, so errors propagated to the caller. Now they're silently swallowed. Worse, on failure the catch block calls this.#controllerSetup.reject(error), leaving #controllerSetup.promise permanently rejected. Every subsequent call to #ensureCanUsePlatform (used by handleRequest, startSnap, installSnaps, etc.) will throw, making the controller permanently unusable with no signal to the caller that clearState failed.


Call
initas part ofclearStateto reinitialize the controller after resetting. This ensures thatisReadyis populated lazily. Additionally adds an argument toinitto disable waiting for the platform to be ready and re-creating thecontrollerSetuppromise.Note
Medium Risk
Changes the controller lifecycle around
clearState/init, which can affect readiness timing and Snap startup behavior; regressions could surface as race conditions if callers assume synchronous platform readiness.Overview
After
clearState,SnapControllernow recreates the internal#controllerSetupdeferred and callsinit(false)to reinitialize the controller (including reinstalling any preinstalled Snaps) rather than leaving it in an uninitialized state.initgains awaitForPlatformflag to optionally avoid awaiting platform readiness (fires#ensureCanUsePlatformin the background and logs errors), and the affected test expectation is updated to reflectisReadybecomingtrueafterclearState.Written by Cursor Bugbot for commit 324eb36. This will update automatically on new commits. Configure here.