MCPcopy
hub / github.com/rpamis/comet / formatCommandErrorDetails

Function formatCommandErrorDetails

src/core/command-error.ts:28–59  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

26}
27
28function formatCommandErrorDetails(error: unknown): string[] {
29 const details: string[] = [];
30 if (!error || typeof error !== 'object') {
31 details.push('Unknown error occurred');
32 return details;
33 }
34
35 const commandError = error as CommandError;
36
37 for (const [label, stream] of [
38 ['stderr', commandError.stderr],
39 ['stdout', commandError.stdout],
40 ] as const) {
41 const cleaned = cleanCommandOutput(streamToText(stream));
42 if (cleaned) {
43 details.push(`${label}:\n${cleaned}`);
44 }
45 }
46
47 if (details.length === 0) {
48 const reason = commandError.killed
49 ? 'Process was killed (likely timed out)'
50 : commandError.code === 'ETIMEDOUT'
51 ? 'Process timed out'
52 : commandError.code === 'ENOENT'
53 ? 'Command not found — check that the required CLI is installed and on PATH'
54 : 'No error output captured';
55 details.push(reason);
56 }
57
58 return details;
59}
60
61function printCommandErrorDetails(error: unknown, indent = ' '): void {
62 for (const detail of formatCommandErrorDetails(error)) {

Callers 2

printCommandErrorDetailsFunction · 0.85

Calls 2

cleanCommandOutputFunction · 0.85
streamToTextFunction · 0.85

Tested by

no test coverage detected