@devries-cameron20 / composio Mirror · read-only / commits / 4e80a8465
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 23, 01:45 UTC

Fix error handling

haxzie committed May 22, 2025 at 18:09 UTC 4e80a8465e8f94e10e25403b4193fa61c2d27b76
3 files changed +60 -70
packages/core/src/errors/ComposioError.ts
+1 -1
@@ -81,7 +81,7 @@ export class ComposioError extends Error {
81 options.statusCode ||
82 (options.cause instanceof BadRequestError ? options.cause.status : undefined);
83
84 - this.code = `TS-SDK:${options.code}`;
84 + this.code = `TS-SDK::${options.code}`;
85 // format the possible fixes
86 this.possibleFixes = options.possibleFixes;
87
packages/core/src/telemetry/Telemetry.ts
+9 -6
@@ -119,7 +119,7 @@ export class TelemetryService {
119 if (error instanceof Error && !error.errorId) {
120 // if there is error id, it means the error is already handled
121 error.errorId = getRandomUUID();
122 - await this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
122 + this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
123 }
124 // @TODO: check if this will send the error telemetry to the server
125 // rethrow the error to be handled by the caller
@@ -148,11 +148,14 @@ export class TelemetryService {
148
149 /**
150 * Prepare and send the error telemetry.
151 + *
152 + * @TODO This currently blocks the thread and sends the telemetry to the server.
153 + *
154 * @param {unknown} error - The error to send.
155 * @param {string} instrumentedClassName - The class name of the instrumented class.
156 * @param {string} name - The name of the method that threw the error.
157 */
155 - private async prepareAndSendErrorTelemetry(
158 + private prepareAndSendErrorTelemetry(
159 error: unknown,
160 instrumentedClassName: string,
161 name: string,
@@ -167,7 +170,7 @@ export class TelemetryService {
170 current_stack: error.stack?.split('\n') || [],
171 description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`,
172 };
170 - await this.sendErrorTelemetry(telemetryPayload);
173 + this.sendErrorTelemetry(telemetryPayload);
174 } else if (error instanceof ComposioError) {
175 // Composio SDK Errors
176 const telemetryPayload: TelemetryErrorPayloadParams = {
@@ -179,7 +182,7 @@ export class TelemetryService {
182 possible_fix: error.possibleFixes?.join('\n'),
183 description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`,
184 };
182 - await this.sendErrorTelemetry(telemetryPayload);
185 + this.sendErrorTelemetry(telemetryPayload);
186 } else if (error instanceof Error) {
187 // Unhandled errors
188 const telemetryPayload: TelemetryErrorPayloadParams = {
@@ -189,7 +192,7 @@ export class TelemetryService {
192 current_stack: error.stack?.split('\n') || [],
193 description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`,
194 };
192 - await this.sendErrorTelemetry(telemetryPayload);
195 + this.sendErrorTelemetry(telemetryPayload);
196 }
197 }
198
@@ -235,7 +238,7 @@ export class TelemetryService {
238 headers: { 'Content-Type': 'application/json' },
239 };
240
238 - await this.transport.send(reqPayload);
241 + this.transport.send(reqPayload);
242 }
243 }
244
packages/core/src/telemetry/transports/ProcessTransport.ts
+50 -63
@@ -3,80 +3,67 @@ import { TelemetryTransportParams } from '../../types/telemetry.types';
3 import logger from '../../utils/logger';
4 import { BaseTelemetryTransport } from '../TelemetryTransport';
5 export class ProcessTelemetryTransport implements BaseTelemetryTransport {
6 - async send(payload: TelemetryTransportParams): Promise<void> {
6 + send(payload: TelemetryTransportParams): Promise<void> {
7 if (typeof window !== 'undefined') {
8 return Promise.reject(
9 new Error('ProcessTelemetryTransport can only be used in Node.js environments')
10 );
11 }
12
13 - try {
14 - await fetch(payload.url, {
15 - method: payload.method,
16 - headers: payload.headers,
17 - body: JSON.stringify(payload.data),
18 - });
19 - logger.debug(chalk.yellow('ProcessTelemetry'), JSON.stringify(payload, null, 2));
20 - } catch (error) {
21 - logger.error('Error sending telemetry', error);
22 - return Promise.resolve();
23 - }
24 -
25 - // return new Promise(resolve => {
26 - // try {
27 - // // use fetch to send the telemetry
28 -
29 - // const url = new URL(payload.url);
30 - // const protocol = url.protocol === 'https:' ? 'https' : 'http';
31 - // const port = url.port || (url.protocol === 'https:' ? 443 : 80);
13 + return new Promise(resolve => {
14 + try {
15 + // use fetch to send the telemetry
16
33 - // const args = [
34 - // '-e',
35 - // `
36 - // const http = require('${protocol}');
37 - // const options = {
38 - // hostname: '${url.hostname}',
39 - // path: '${url.pathname}${url.search}',
40 - // port: ${port},
41 - // method: '${payload.method}',
42 - // headers: ${JSON.stringify(payload.headers)}
43 - // };
17 + const url = new URL(payload.url);
18 + const protocol = url.protocol === 'https:' ? 'https' : 'http';
19 + const port = url.port || (url.protocol === 'https:' ? 443 : 80);
20
45 - // const req = http.request(options, (res) => {
46 - // res.on('data', () => {});
47 - // res.on('end', () => {
48 - // process.exit(0);
49 - // });
50 - // });
21 + const args = [
22 + '-e',
23 + `
24 + const http = require('${protocol}');
25 + const options = {
26 + hostname: '${url.hostname}',
27 + path: '${url.pathname}${url.search}',
28 + port: ${port},
29 + method: '${payload.method}',
30 + headers: ${JSON.stringify(payload.headers)}
31 + };
32
52 - // req.on('error', () => {
33 + const req = http.request(options, (res) => {
34 + res.on('data', () => {});
35 + res.on('end', () => {
36 + process.exit(0);
37 + });
38 + });
39
54 - // process.exit(0);
55 - // });
40 + req.on('error', () => {
41 + process.exit(0);
42 + });
43
57 - // req.write(JSON.stringify(${JSON.stringify(payload.data)}));
58 - // req.end();
59 - // `,
60 - // ];
44 + req.write(JSON.stringify(${JSON.stringify(payload.data)}));
45 + req.end();
46 + `,
47 + ];
48
62 - // import('child_process')
63 - // .then(({ spawn }) => {
64 - // spawn('node', args, {
65 - // stdio: 'ignore',
66 - // detached: false,
67 - // shell: false,
68 - // }).unref();
69 - // resolve();
70 - // })
71 - // .catch(error => {
72 - // logger.error('Error sending telemetry', error);
73 - // resolve();
74 - // });
75 - // logger.debug(chalk.yellow('Process Telemetry'), JSON.stringify(payload, null, 2));
76 - // } catch (error) {
77 - // logger.error('Error sending telemetry', error);
78 - // resolve();
79 - // }
80 - // });
49 + import('child_process')
50 + .then(({ spawn }) => {
51 + spawn('node', args, {
52 + stdio: 'ignore',
53 + detached: false,
54 + shell: false,
55 + }).unref();
56 + resolve();
57 + })
58 + .catch(error => {
59 + logger.error('Error sending telemetry', error);
60 + resolve();
61 + });
62 + logger.debug(chalk.yellow('Process Telemetry'), JSON.stringify(payload, null, 2));
63 + } catch (error) {
64 + logger.error('Error sending telemetry', error);
65 + resolve();
66 + }
67 + });
68 }
69 }