Skip to content

Commit 7767260

Browse files
authored
refactor(core): centralize plugin unmount error boundary and fix console telemetry (#2422)
1 parent 74f20c6 commit 7767260

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/lib/acode.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,15 @@ class Acode {
733733

734734
unmountPlugin(id) {
735735
if (id in this.#pluginUnmount) {
736-
this.#pluginUnmount[id]();
736+
try {
737+
this.#pluginUnmount[id]();
738+
} catch (err) {
739+
console.group(
740+
`Error while calling unmount callback for plugin "${id}"`,
741+
);
742+
console.error(err);
743+
console.groupEnd();
744+
}
737745
fsOperation(Url.join(CACHE_STORAGE, id)).delete();
738746
}
739747

src/lib/loadPlugin.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ export default async function loadPlugin(pluginId, justInstalled = false) {
1616
// listeners, etc. — is lost and can never be called. Letting the framework
1717
// invoke unmountPlugin() first ensures the OLD destroy() runs while it still
1818
// exists, so all old-version resources are properly cleaned up.
19-
try {
20-
acode.unmountPlugin(pluginId);
21-
} catch (e) {
22-
// unmountPlugin() itself is safe when no callback is registered (it no-ops),
23-
// but a plugin's destroy() callback may throw. We catch here so a faulty
24-
// cleanup in the old version does not block reloading the new one.
25-
console.error(`Error while unmounting plugin "${pluginId}":`, e);
26-
}
19+
acode.unmountPlugin(pluginId);
2720

2821
// Remove the old <script> tag so the browser fetches the new source.
2922
const oldScript = document.getElementById(`${pluginId}-mainScript`);

0 commit comments

Comments
 (0)