Skip to content

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

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

jkomyno142bcc7bf352
diff --git a/ts/e2e-tests/_utils/src/index.ts b/ts/e2e-tests/_utils/src/index.ts
index bfe3197c1..151b20535 100644
--- a/ts/e2e-tests/_utils/src/index.ts
+++ b/ts/e2e-tests/_utils/src/index.ts
@@ -13,4 +13,4 @@ export type {
SkipInCI,
} from './types';
export { e2e } from './e2e';
-export { sanitizeOutput } from './sanitize';
+export { sanitizeOutput, parseJsonStdout } from './sanitize';
diff --git a/ts/e2e-tests/_utils/src/sanitize.ts b/ts/e2e-tests/_utils/src/sanitize.ts
index 952649899..c2ef5d04b 100644
--- a/ts/e2e-tests/_utils/src/sanitize.ts
+++ b/ts/e2e-tests/_utils/src/sanitize.ts
@@ -2,6 +2,8 @@
* Output sanitization utilities for stable test comparisons.
*/
+import type { E2ETestResult } from './types';
+
/**
* Sanitize command output for stable comparisons.
* Removes ANSI escape codes, normalizes line endings, and trims leading/trailing
@@ -21,3 +23,34 @@ export function sanitizeOutput(output: string): string {
.trim()
);
}
+
+/**
+ * Parse JSON from a command's stdout, providing a clear error message on failure.
+ *
+ * When the CLI errors out (e.g. 401), stdout is empty and `JSON.parse("")` throws
+ * a cryptic `SyntaxError: Unexpected EOF`. This helper surfaces the actual exit code
+ * and stderr so the root cause is immediately visible.
+ */
+export function parseJsonStdout(result: E2ETestResult): unknown {
+ const raw = sanitizeOutput(result.stdout);
+ if (raw === '') {
+ const stderrPreview = sanitizeOutput(result.stderr).slice(0, 300);
+ throw new Error(
+ `stdout was empty — cannot parse JSON.\n` +
+ ` exitCode: ${result.exitCode}\n` +
+ ` stderr: ${stderrPreview || '(empty)'}`
+ );
+ }
+ try {
+ return JSON.parse(raw);
+ } catch (cause) {
+ const stderrPreview = sanitizeOutput(result.stderr).slice(0, 300);
+ throw new Error(
+ `stdout was not valid JSON.\n` +
+ ` exitCode: ${result.exitCode}\n` +
+ ` stdout: ${raw.slice(0, 300)}\n` +
+ ` stderr: ${stderrPreview || '(empty)'}`,
+ { cause }
+ );
+ }
+}