diff --git a/packages/opencode/src/bus/index.ts b/packages/opencode/src/bus/index.ts index 81cdbab1394..9aff2bd63e2 100644 --- a/packages/opencode/src/bus/index.ts +++ b/packages/opencode/src/bus/index.ts @@ -125,9 +125,7 @@ export const layer = Layer.effect( const ps = yield* getOrCreate(s, def) const subscription = yield* PubSub.subscribe(ps) yield* Effect.addFinalizer(() => - Effect.sync(() => - Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: def.type } })), - ), + Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: def.type } })), ) return Stream.fromSubscription(subscription) }) @@ -138,9 +136,7 @@ export const layer = Layer.effect( const s = yield* InstanceState.get(state) const subscription = yield* PubSub.subscribe(s.wildcard) yield* Effect.addFinalizer(() => - Effect.sync(() => - Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: "*" } })), - ), + Effect.logInfo("unsubscribing").pipe(Effect.annotateLogs({ service: "bus", ...{ type: "*" } })), ) return Stream.fromSubscription(subscription) }) @@ -157,15 +153,25 @@ export const layer = Layer.effect( Stream.runForEach((msg) => Effect.tryPromise({ try: () => Promise.resolve().then(() => callback(msg)), - catch: (cause) => {}, - }).pipe(Effect.ignore), + catch: (cause) => cause, + }).pipe( + Effect.tapError((cause) => + Effect.logError("subscriber failed").pipe(Effect.annotateLogs({ service: "bus", ...{ type, cause } })), + ), + Effect.ignore, + ), ), Effect.forkScoped, ), ) return () => { - bridge.fork(Scope.close(scope, Exit.void)) + bridge.fork( + Effect.logInfo("unsubscribing").pipe( + Effect.annotateLogs({ service: "bus", ...{ type } }), + Effect.andThen(Scope.close(scope, Exit.void)), + ), + ) } }) } diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.ts index f4aa1ed7b9b..9a61f0935f4 100644 --- a/packages/opencode/src/plugin/index.ts +++ b/packages/opencode/src/plugin/index.ts @@ -153,8 +153,15 @@ export const layer = Layer.effect( ) const init = yield* Effect.tryPromise({ try: () => plugin(input), - catch: (err) => {}, - }).pipe(Effect.option) + catch: (error) => error, + }).pipe( + Effect.tapError((error) => + Effect.logError("failed to load internal plugin").pipe( + Effect.annotateLogs({ service: "plugin", ...{ name: plugin.name, error } }), + ), + ), + Effect.option, + ) if (init._tag === "Some") hooks.push(init.value) } @@ -210,6 +217,11 @@ export const layer = Layer.effect( return message }, }).pipe( + Effect.tapError((error) => + Effect.logError("failed to load plugin").pipe( + Effect.annotateLogs({ service: "plugin", ...{ path: load.spec, error } }), + ), + ), Effect.catch(() => { // TODO: make proper events for this // bus.publish(Session.Event.Error, { @@ -226,8 +238,13 @@ export const layer = Layer.effect( for (const hook of hooks) { yield* Effect.tryPromise({ try: () => Promise.resolve((hook as any).config?.(cfg)), - catch: (err) => {}, - }).pipe(Effect.ignore) + catch: (error) => error, + }).pipe( + Effect.tapError((error) => + Effect.logError("plugin config hook failed").pipe(Effect.annotateLogs({ service: "plugin", ...{ error } })), + ), + Effect.ignore, + ) } // Subscribe to bus events, fiber interrupted when scope closes