@@ -19,6 +19,8 @@ import { BunProc } from "@/bun"
1919import { Installation } from "@/installation"
2020import { ConfigMarkdown } from "./markdown"
2121import { existsSync } from "fs"
22+ import { Bus } from "@/bus"
23+ import { Session } from "@/session"
2224
2325export namespace Config {
2426 const log = Log . create ( { service : "config" } )
@@ -231,8 +233,15 @@ export namespace Config {
231233 dot : true ,
232234 cwd : dir ,
233235 } ) ) {
234- const md = await ConfigMarkdown . parse ( item )
235- if ( ! md . data ) continue
236+ const md = await ConfigMarkdown . parse ( item ) . catch ( ( err ) => {
237+ const message = ConfigMarkdown . FrontmatterError . isInstance ( err )
238+ ? `${ err . data . path } : ${ err . data . message } `
239+ : `Failed to parse command ${ item } `
240+ Bus . publish ( Session . Event . Error , { error : new NamedError . Unknown ( { message } ) . toObject ( ) } )
241+ log . error ( "failed to load command" , { command : item , err } )
242+ return undefined
243+ } )
244+ if ( ! md ) continue
236245
237246 const patterns = [ "/.opencode/command/" , "/.opencode/commands/" , "/command/" , "/commands/" ]
238247 const file = rel ( item , patterns ) ?? path . basename ( item )
@@ -263,8 +272,15 @@ export namespace Config {
263272 dot : true ,
264273 cwd : dir ,
265274 } ) ) {
266- const md = await ConfigMarkdown . parse ( item )
267- if ( ! md . data ) continue
275+ const md = await ConfigMarkdown . parse ( item ) . catch ( ( err ) => {
276+ const message = ConfigMarkdown . FrontmatterError . isInstance ( err )
277+ ? `${ err . data . path } : ${ err . data . message } `
278+ : `Failed to parse agent ${ item } `
279+ Bus . publish ( Session . Event . Error , { error : new NamedError . Unknown ( { message } ) . toObject ( ) } )
280+ log . error ( "failed to load agent" , { agent : item , err } )
281+ return undefined
282+ } )
283+ if ( ! md ) continue
268284
269285 const patterns = [ "/.opencode/agent/" , "/.opencode/agents/" , "/agent/" , "/agents/" ]
270286 const file = rel ( item , patterns ) ?? path . basename ( item )
@@ -294,8 +310,15 @@ export namespace Config {
294310 dot : true ,
295311 cwd : dir ,
296312 } ) ) {
297- const md = await ConfigMarkdown . parse ( item )
298- if ( ! md . data ) continue
313+ const md = await ConfigMarkdown . parse ( item ) . catch ( ( err ) => {
314+ const message = ConfigMarkdown . FrontmatterError . isInstance ( err )
315+ ? `${ err . data . path } : ${ err . data . message } `
316+ : `Failed to parse mode ${ item } `
317+ Bus . publish ( Session . Event . Error , { error : new NamedError . Unknown ( { message } ) . toObject ( ) } )
318+ log . error ( "failed to load mode" , { mode : item , err } )
319+ return undefined
320+ } )
321+ if ( ! md ) continue
299322
300323 const config = {
301324 name : path . basename ( item , ".md" ) ,
0 commit comments