@@ -513,7 +513,13 @@ export function fromPromise(plugin: Plugin) {
513513 hook : ( name , callback ) =>
514514 register (
515515 host . tool . hook ( name , ( event ) => {
516- const result = Effect . tryPromise ( { try : ( ) => Promise . resolve ( callback ( event ) ) , catch : toolError } )
516+ const result = Effect . tryPromise ( {
517+ try : ( ) => Promise . resolve ( callback ( event ) ) ,
518+ catch : ( error ) =>
519+ error instanceof Tool . Error
520+ ? error
521+ : new Tool . Error ( { message : error instanceof Error ? error . message : String ( error ) , error } ) ,
522+ } )
517523 // Only execute.before may reject a call; it fails that call alone, like an Effect hook. The
518524 // check cannot narrow the generic name, so the declared failure type is restated.
519525 return ( name === "execute.before" ? result : Effect . orDie ( result ) ) as Effect . Effect <
@@ -636,11 +642,6 @@ function attempt<A>(evaluate: (signal: AbortSignal) => PromiseLike<A>) {
636642
637643type RuntimeSchema = Schema . Codec < unknown , unknown >
638644
639- const toolError = ( error : unknown ) =>
640- error instanceof Tool . Error
641- ? error
642- : new Tool . Error ( { message : error instanceof Error ? error . message : String ( error ) , error } )
643-
644645const executePromiseTool = ( tool : Info , input : any , context : Tool . Context ) =>
645646 Effect . tryPromise ( {
646647 try : ( signal ) =>
@@ -649,5 +650,8 @@ const executePromiseTool = (tool: Info, input: any, context: Tool.Context) =>
649650 signal,
650651 progress : ( update ) => Effect . runPromise ( context . progress ( update ) , { signal } ) ,
651652 } ) ,
652- catch : toolError ,
653+ catch : ( error ) =>
654+ error instanceof Tool . Error
655+ ? error
656+ : new Tool . Error ( { message : error instanceof Error ? error . message : String ( error ) , error } ) ,
653657 } )
0 commit comments