Skip to content

Commit ec263d6

Browse files
neriousyFilip Hejmowski
andauthored
fix(core): keep plugin swaps going when a cleanup fails (#63548)
Co-authored-by: Filip Hejmowski <fhejmowski@simplito.com>
1 parent 96d9501 commit ec263d6

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎packages/core/src/plugin.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,14 @@ const layer = Layer.effect(
143143
([id, slot]) =>
144144
Effect.gen(function* () {
145145
active.delete(id)
146-
if (slot.activation && !slot.activation.failure)
147-
yield* Scope.close(slot.activation.scope, Exit.void)
146+
if (!slot.activation || slot.activation.failure) return
147+
// Later plugins, including the config agents and commands, are already closed. A failing
148+
// finalizer must not abort the swap, or they stay unregistered until the next reload.
149+
yield* Scope.close(slot.activation.scope, Exit.void).pipe(
150+
Effect.catchCause((cause) =>
151+
Effect.logError("failed to clean up plugin", { "plugin.id": id, cause }),
152+
),
153+
)
148154
}),
149155
{ discard: true },
150156
)

‎packages/plugin/src/promise/adapter.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ export function fromPromise(plugin: Plugin) {
672672

673673
yield* Effect.acquireRelease(
674674
Effect.promise(() => Promise.resolve(plugin.setup(context2))),
675-
(cleanup) => (cleanup ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void),
675+
// JavaScript plugins may return anything, such as a v1-style hooks object; only a function is a cleanup.
676+
(cleanup) => (typeof cleanup === "function" ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void),
676677
)
677678
}),
678679
})

0 commit comments

Comments
 (0)