@@ -7,6 +7,7 @@ import { SimApiError } from '../../http/client'
77import { readNdjson } from '../../http/ndjson'
88import { safeOneLine , sanitize } from '../../output/render'
99import { executeOperation , runFailureMessage } from '../../runtime/execute'
10+ import { retypeApiError } from '../../runtime/naming'
1011import { buildRequest } from '../../runtime/request'
1112import { renderResult } from '../../runtime/result'
1213import type { OperationSpec } from '../../runtime/types'
@@ -154,21 +155,27 @@ async function runWithResultStream(workflowId: string, command: Command): Promis
154155 const flags = command . optsWithGlobals ( ) as Record < string , unknown >
155156 const { client, profile } = clientFrom ( command )
156157 const operation = V2_OPERATIONS . executeWorkflow as OperationSpec
157- const request = buildRequest ( 'executeWorkflow' , [ workflowId ] , flags , profile . workspaceId )
158- const response = await client . requestRaw ( request . path , {
159- method : operation . method ,
160- query : request . query ,
161- body : request . body ,
162- headers : { ...request . headers , accept : WORKFLOW_RESULT_STREAM_CONTENT_TYPE } ,
163- } )
164- const payload = await readWorkflowResult ( response )
158+ const commandSpec = CLI_CONTRACT . executeWorkflow ?? { }
165159
166- renderResult ( 'executeWorkflow' , profile . output , payload , CLI_CONTRACT . executeWorkflow ?? { } , {
167- expandedTrace : flags . trace === true ,
168- } )
169-
170- const failure = runFailureMessage ( 'executeWorkflow' , payload )
171- if ( failure ) throw new SimApiError ( failure , 0 )
160+ try {
161+ const request = buildRequest ( 'executeWorkflow' , [ workflowId ] , flags , profile . workspaceId )
162+ const response = await client . requestRaw ( request . path , {
163+ method : operation . method ,
164+ query : request . query ,
165+ body : request . body ,
166+ headers : { ...request . headers , accept : WORKFLOW_RESULT_STREAM_CONTENT_TYPE } ,
167+ } )
168+ const payload = await readWorkflowResult ( response )
169+
170+ renderResult ( 'executeWorkflow' , profile . output , payload , commandSpec , {
171+ expandedTrace : flags . trace === true ,
172+ } )
173+
174+ const failure = runFailureMessage ( 'executeWorkflow' , payload )
175+ if ( failure ) throw new SimApiError ( failure , 0 )
176+ } catch ( error ) {
177+ throw retypeApiError ( error , 'executeWorkflow' , commandSpec , operation )
178+ }
172179}
173180
174181/**
0 commit comments