(msg: CallMessage)
| 69 | }); |
| 70 | |
| 71 | const serve = async (msg: CallMessage): Promise<void> => { |
| 72 | // Test-only crash hook so the pool's worker-recovery path is exercisable |
| 73 | // deterministically. Gated behind an env flag only the suite sets — inert in |
| 74 | // normal operation (and `__test_crash__` isn't a real tool name anyway). |
| 75 | if (msg.toolName === '__test_crash__' && process.env.CODEGRAPH_QUERY_WORKER_ALLOW_TEST_CRASH === '1') { |
| 76 | process.exit(13); |
| 77 | } |
| 78 | if (!handler) { |
| 79 | port.postMessage({ |
| 80 | type: 'result', |
| 81 | id: msg.id, |
| 82 | result: errorResult(`codegraph worker could not open the project: ${initError}`), |
| 83 | }); |
| 84 | return; |
| 85 | } |
| 86 | try { |
| 87 | // executeReadTool already classifies NotIndexed/PathRefusal/internal errors |
| 88 | // into a ToolResult and never throws — the catch is belt-and-suspenders. |
| 89 | const result: ToolResult = await handler.executeReadTool(msg.toolName, msg.args); |
| 90 | port.postMessage({ type: 'result', id: msg.id, result }); |
| 91 | } catch (err) { |
| 92 | port.postMessage({ |
| 93 | type: 'result', |
| 94 | id: msg.id, |
| 95 | result: errorResult(err instanceof Error ? err.message : String(err)), |
| 96 | }); |
| 97 | } |
| 98 | }; |
| 99 | } |
| 100 | |
| 101 | function errorResult(text: string): ToolResult { |
no test coverage detected