@@ -401,27 +401,11 @@ export async function executeCustomToolCall(
401401 } ,
402402 autoInsertEndStepParam,
403403 } )
404- if ( 'error' in toolCall ) {
405- const toolResult : ToolMessage = {
406- role : 'tool' ,
407- toolName,
408- toolCallId : toolCall . toolCallId ,
409- content : jsonToolResult ( {
410- errorMessage : toolCall . error ,
411- } ) ,
412- }
413- toolResults . push ( cloneDeep ( toolResult ) )
414- toolResultsToAddAfterStream . push ( cloneDeep ( toolResult ) )
415- logger . debug (
416- { toolCall, error : toolCall . error } ,
417- `${ toolName } error: ${ toolCall . error } ` ,
418- )
419- return previousToolCallFinished
420- }
421404
422405 // Filter out restricted tools - emit error instead of tool call/result
423406 // This prevents the CLI from showing tool calls that the agent doesn't have permission to use
424407 if (
408+ toolCall . toolName &&
425409 ! ( agentTemplate . toolNames as string [ ] ) . includes ( toolCall . toolName ) &&
426410 ! fromHandleSteps &&
427411 ! (
@@ -438,6 +422,24 @@ export async function executeCustomToolCall(
438422 return previousToolCallFinished
439423 }
440424
425+ if ( 'error' in toolCall ) {
426+ const toolResult : ToolMessage = {
427+ role : 'tool' ,
428+ toolName,
429+ toolCallId : toolCall . toolCallId ,
430+ content : jsonToolResult ( {
431+ errorMessage : toolCall . error ,
432+ } ) ,
433+ }
434+ toolResults . push ( cloneDeep ( toolResult ) )
435+ toolResultsToAddAfterStream . push ( cloneDeep ( toolResult ) )
436+ logger . debug (
437+ { toolCall, error : toolCall . error } ,
438+ `${ toolName } error: ${ toolCall . error } ` ,
439+ )
440+ return previousToolCallFinished
441+ }
442+
441443 // Only emit tool_call event after permission check passes
442444 onResponseChunk ( {
443445 type : 'tool_call' ,
0 commit comments