MCPcopy
hub / github.com/afar1/fieldtheory-cli / buildMessage

Function buildMessage

src/engine.ts:321–347  ·  view source on GitHub ↗

Build a user-facing failure message. Deliberately does NOT inline the * prompt — see EngineInvocationError for why.

(
  engineName: string,
  reason: 'timeout' | 'maxbuffer' | 'exit' | 'spawn',
  stderr: string,
  code: number | null,
  signal: NodeJS.Signals | null,
  timeoutMs: number,
)

Source from the content-addressed store, hash-verified

319/** Build a user-facing failure message. Deliberately does NOT inline the
320 * prompt — see EngineInvocationError for why. */
321function buildMessage(
322 engineName: string,
323 reason: 'timeout' | 'maxbuffer' | 'exit' | 'spawn',
324 stderr: string,
325 code: number | null,
326 signal: NodeJS.Signals | null,
327 timeoutMs: number,
328): string {
329 const stderrSnippet = stderr.trim().slice(-500);
330 const detail = stderrSnippet ? ` \u2014 ${stderrSnippet}` : '';
331 switch (reason) {
332 case 'timeout': {
333 const duration = timeoutMs < 1000 ? `${timeoutMs}ms` : `${Math.round(timeoutMs / 1000)}s`;
334 return `${engineName} timed out after ${duration}${detail}`;
335 }
336 case 'maxbuffer':
337 return `${engineName} output exceeded buffer cap${detail}`;
338 case 'spawn':
339 return `${engineName} failed to start${detail}`;
340 case 'exit':
341 default: {
342 const signalPart = signal ? ` (signal ${signal})` : '';
343 const codePart = code !== null ? ` exit ${code}` : '';
344 return `${engineName} failed${codePart}${signalPart}${detail}`;
345 }
346 }
347}
348
349/**
350 * Synchronous engine call — uses `spawnSync` with `input: ''` so the child's

Callers 2

invokeEngineFunction · 0.85
invokeEngineAsyncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected