@devries-cameron20 / composio Mirror · read-only / commits / 142bcc7bf
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 04:30 UTC

fix(e2e): add parseJsonStdout helper for clear error messages

When the CLI errors out, stdout is empty and JSON.parse("") throws a cryptic SyntaxError. The new helper surfaces the actual exit code and stderr so the root cause is immediately visible in test output.

jkomyno committed Mar 9, 2026 at 14:07 UTC 142bcc7bf35251c057fe576e14e21f760d956354
2 files changed +34 -1
ts/e2e-tests/_utils/src/index.ts
+1 -1
@@ -13,4 +13,4 @@ export type {
13 SkipInCI,
14 } from './types';
15 export { e2e } from './e2e';
16 -export { sanitizeOutput } from './sanitize';
16 +export { sanitizeOutput, parseJsonStdout } from './sanitize';
ts/e2e-tests/_utils/src/sanitize.ts
+33
@@ -2,6 +2,8 @@
2 * Output sanitization utilities for stable test comparisons.
3 */
4
5 +import type { E2ETestResult } from './types';
6 +
7 /**
8 * Sanitize command output for stable comparisons.
9 * Removes ANSI escape codes, normalizes line endings, and trims leading/trailing
@@ -21,3 +23,34 @@ export function sanitizeOutput(output: string): string {
23 .trim()
24 );
25 }
26 +
27 +/**
28 + * Parse JSON from a command's stdout, providing a clear error message on failure.
29 + *
30 + * When the CLI errors out (e.g. 401), stdout is empty and `JSON.parse("")` throws
31 + * a cryptic `SyntaxError: Unexpected EOF`. This helper surfaces the actual exit code
32 + * and stderr so the root cause is immediately visible.
33 + */
34 +export function parseJsonStdout(result: E2ETestResult): unknown {
35 + const raw = sanitizeOutput(result.stdout);
36 + if (raw === '') {
37 + const stderrPreview = sanitizeOutput(result.stderr).slice(0, 300);
38 + throw new Error(
39 + `stdout was empty — cannot parse JSON.\n` +
40 + ` exitCode: ${result.exitCode}\n` +
41 + ` stderr: ${stderrPreview || '(empty)'}`
42 + );
43 + }
44 + try {
45 + return JSON.parse(raw);
46 + } catch (cause) {
47 + const stderrPreview = sanitizeOutput(result.stderr).slice(0, 300);
48 + throw new Error(
49 + `stdout was not valid JSON.\n` +
50 + ` exitCode: ${result.exitCode}\n` +
51 + ` stdout: ${raw.slice(0, 300)}\n` +
52 + ` stderr: ${stderrPreview || '(empty)'}`,
53 + { cause }
54 + );
55 + }
56 +}