(
opts: InvokeOptions,
invoke: (client: DaemonClient) => Promise<TResult>,
context: {
label: string;
errorTitle: string;
captureInfraErrorMetric: (error: unknown) => void;
captureInvocationMetric: (outcome: SentryToolInvocationOutcome) => void;
consumeResult: (result: TResult) => void;
postProcessParams: {
tool: ToolDefinition;
catalog: ToolCatalog;
runtime: InvokeOptions['runtime'];
};
},
)
| 328 | } |
| 329 | |
| 330 | private async invokeViaDaemon<TResult>( |
| 331 | opts: InvokeOptions, |
| 332 | invoke: (client: DaemonClient) => Promise<TResult>, |
| 333 | context: { |
| 334 | label: string; |
| 335 | errorTitle: string; |
| 336 | captureInfraErrorMetric: (error: unknown) => void; |
| 337 | captureInvocationMetric: (outcome: SentryToolInvocationOutcome) => void; |
| 338 | consumeResult: (result: TResult) => void; |
| 339 | postProcessParams: { |
| 340 | tool: ToolDefinition; |
| 341 | catalog: ToolCatalog; |
| 342 | runtime: InvokeOptions['runtime']; |
| 343 | }; |
| 344 | }, |
| 345 | ): Promise<void> { |
| 346 | const session = opts.renderSession!; |
| 347 | const socketPath = opts.socketPath; |
| 348 | if (!socketPath) { |
| 349 | const error = new Error('SocketPathMissing'); |
| 350 | context.captureInfraErrorMetric(error); |
| 351 | context.captureInvocationMetric('infra_error'); |
| 352 | emitExplicitRuntimeError({ |
| 353 | session, |
| 354 | handlerContext: opts.handlerContext, |
| 355 | onStructuredOutput: opts.onStructuredOutput, |
| 356 | code: 'SOCKET_PATH_MISSING', |
| 357 | message: 'Socket path required: No socket path configured for daemon communication.', |
| 358 | }); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | const daemonTimeout = |
| 363 | context.postProcessParams.tool.workflow === 'xcode-ide' ? 60_000 : undefined; |
| 364 | const client = new DaemonClient({ socketPath, timeout: daemonTimeout }); |
| 365 | const isRunning = await client.isRunning(); |
| 366 | |
| 367 | if (!isRunning) { |
| 368 | try { |
| 369 | await ensureDaemonRunning({ |
| 370 | socketPath, |
| 371 | workspaceRoot: opts.workspaceRoot, |
| 372 | startupTimeoutMs: opts.daemonStartupTimeoutMs ?? DEFAULT_DAEMON_STARTUP_TIMEOUT_MS, |
| 373 | env: buildDaemonEnvOverrides(opts), |
| 374 | }); |
| 375 | } catch (error) { |
| 376 | log( |
| 377 | 'error', |
| 378 | `[infra/tool-invoker] ${context.label} daemon auto-start failed (${getErrorKind(error)})`, |
| 379 | { sentry: true }, |
| 380 | ); |
| 381 | context.captureInfraErrorMetric(error); |
| 382 | context.captureInvocationMetric('infra_error'); |
| 383 | emitExplicitRuntimeError({ |
| 384 | session, |
| 385 | handlerContext: opts.handlerContext, |
| 386 | onStructuredOutput: opts.onStructuredOutput, |
| 387 | code: 'DAEMON_AUTO_START_FAILED', |
no test coverage detected