diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index eb0e363e05a..f7cb7268915 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -568,8 +568,12 @@ export namespace Config { const message = text ? `Config file at ${item} is invalid: ${text}` : `Config file at ${item} is invalid` const err = new InvalidError({ path: item, issues }, { cause }) if (warnings) warnings.push({ path: item, message, detail: text || undefined }) - const { Session } = await import("@/session") - Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + try { + const { Session } = await import("@/session") + Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + } catch (e) { + log.warn("could not publish session error", { message, err: e }) + } if (kind === "command") { log.error("failed to load command", { command: item, err, message }) return @@ -593,8 +597,12 @@ export namespace Config { ? err.data.message : `Failed to parse command ${item}` if (warnings) warnings.push({ path: item, message }) // kilocode_change - const { Session } = await import("@/session") - Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + try { + const { Session } = await import("@/session") + Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + } catch (e) { + log.warn("could not publish session error", { message, err: e }) + } log.error("failed to load command", { command: item, err }) return undefined }) @@ -646,8 +654,12 @@ export namespace Config { ? err.data.message : `Failed to parse agent ${item}` if (warnings) warnings.push({ path: item, message }) // kilocode_change - const { Session } = await import("@/session") - Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + try { + const { Session } = await import("@/session") + Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + } catch (e) { + log.warn("could not publish session error", { message, err: e }) + } log.error("failed to load agent", { agent: item, err }) return undefined }) @@ -700,8 +712,12 @@ export namespace Config { ? err.data.message : `Failed to parse mode ${item}` if (warnings) warnings.push({ path: item, message }) // kilocode_change - const { Session } = await import("@/session") - Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + try { + const { Session } = await import("@/session") + Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }) + } catch (e) { + log.warn("could not publish session error", { message, err: e }) + } log.error("failed to load mode", { mode: item, err }) return undefined }) diff --git a/packages/opencode/test/kilocode/config-resilience.test.ts b/packages/opencode/test/kilocode/config-resilience.test.ts index 7e48d68dec9..5cb72a91385 100644 --- a/packages/opencode/test/kilocode/config-resilience.test.ts +++ b/packages/opencode/test/kilocode/config-resilience.test.ts @@ -1,6 +1,5 @@ import { afterEach, describe, expect, test } from "bun:test" import path from "path" -import { Bus } from "../../src/bus" import { Config } from "../../src/config/config" import { Instance } from "../../src/project/instance" import { Filesystem } from "../../src/util/filesystem" @@ -47,7 +46,7 @@ Valid agent prompt`, }) }) - test("publishes an error for invalid agent markdown configs", async () => { + test("reports a warning for invalid agent markdown configs", async () => { await using tmp = await tmpdir({ init: async (dir) => { await Filesystem.write( @@ -63,22 +62,10 @@ Broken agent prompt`, await Instance.provide({ directory: tmp.path, fn: async () => { - const seen: Array<{ type: string; properties: { error: { name: string; data: { message: string } } } }> = [] - const unsub = Bus.subscribeAll((event) => { - if (event.type === "session.error") seen.push(event) - }) - await Config.get() - unsub() + const warns = await Config.warnings() - expect( - seen.some( - (item) => - item.properties.error.name === "UnknownError" && - item.properties.error.data.message.includes("skip.md") && - item.properties.error.data.message.includes("mode"), - ), - ).toBe(true) + expect(warns.some((w) => w.path.includes("skip.md") && w.message.includes("mode"))).toBe(true) }, }) }) @@ -117,7 +104,7 @@ Valid command template`, }) }) - test("publishes an error for invalid command markdown configs", async () => { + test("reports a warning for invalid command markdown configs", async () => { await using tmp = await tmpdir({ init: async (dir) => { await Filesystem.write( @@ -133,22 +120,10 @@ Broken command template`, await Instance.provide({ directory: tmp.path, fn: async () => { - const seen: Array<{ type: string; properties: { error: { name: string; data: { message: string } } } }> = [] - const unsub = Bus.subscribeAll((event) => { - if (event.type === "session.error") seen.push(event) - }) - await Config.get() - unsub() + const warns = await Config.warnings() - expect( - seen.some( - (item) => - item.properties.error.name === "UnknownError" && - item.properties.error.data.message.includes("skip.md") && - item.properties.error.data.message.includes("subtask"), - ), - ).toBe(true) + expect(warns.some((w) => w.path.includes("skip.md") && w.message.includes("subtask"))).toBe(true) }, }) })