mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-14 20:21:39 +03:00
fix(core): keep plugin swaps going when a cleanup fails (#63548)
Co-authored-by: Filip Hejmowski <fhejmowski@simplito.com>
This commit is contained in:
@@ -143,8 +143,14 @@ const layer = Layer.effect(
|
||||
([id, slot]) =>
|
||||
Effect.gen(function* () {
|
||||
active.delete(id)
|
||||
if (slot.activation && !slot.activation.failure)
|
||||
yield* Scope.close(slot.activation.scope, Exit.void)
|
||||
if (!slot.activation || slot.activation.failure) return
|
||||
// Later plugins, including the config agents and commands, are already closed. A failing
|
||||
// finalizer must not abort the swap, or they stay unregistered until the next reload.
|
||||
yield* Scope.close(slot.activation.scope, Exit.void).pipe(
|
||||
Effect.catchCause((cause) =>
|
||||
Effect.logError("failed to clean up plugin", { "plugin.id": id, cause }),
|
||||
),
|
||||
)
|
||||
}),
|
||||
{ discard: true },
|
||||
)
|
||||
|
||||
@@ -672,7 +672,8 @@ export function fromPromise(plugin: Plugin) {
|
||||
|
||||
yield* Effect.acquireRelease(
|
||||
Effect.promise(() => Promise.resolve(plugin.setup(context2))),
|
||||
(cleanup) => (cleanup ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void),
|
||||
// JavaScript plugins may return anything, such as a v1-style hooks object; only a function is a cleanup.
|
||||
(cleanup) => (typeof cleanup === "function" ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void),
|
||||
)
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user