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
Update error handling demo
haxzie committed
May 23, 2025 at 17:19 UTC
4b6916e90fea17e7f831a114fad161e949818090
1 file changed
+16
-8
packages/core/src/errors/ComposioError.ts
+16
-8
@@ -94,10 +94,11 @@ export class ComposioError extends Error {
94
// Node.js by default shows all the properties of the error object, so we are doing it conditionally
95
this.definePropertyIfExists('statusCode', statusCode);
96
this.definePropertyIfExists('cause', options.cause);
97
-
98
- const combinedStack = options.cause instanceof Error
99
- ? ComposioError.combineStackTraces(options.cause.stack, this.stack)
100
- : options.stack || this.stack;
97
+
98
+ const combinedStack =
99
+ options.cause instanceof Error
100
+ ? ComposioError.combineStackTraces(options.cause.stack, this.stack)
101
+ : options.stack || this.stack;
102
this.definePropertyIfExists('stack', combinedStack);
103
104
if (options.meta && Object.keys(options.meta).length > 0) {
@@ -121,7 +122,7 @@ export class ComposioError extends Error {
122
});
123
}
124
}
124
-
125
+
126
/**
127
* Helper method to combine stack traces when wrapping errors
128
* This ensures the full call chain is preserved
@@ -130,14 +131,17 @@ export class ComposioError extends Error {
131
* @returns Combined stack trace
132
* @private
133
*/
133
- private static combineStackTraces(originalStack?: string, currentStack?: string): string | undefined {
134
+ private static combineStackTraces(
135
+ originalStack?: string,
136
+ currentStack?: string
137
+ ): string | undefined {
138
if (!originalStack) return currentStack;
139
if (!currentStack) return originalStack;
140
141
const currentHeader = currentStack.split('\n')[0];
142
const originalStackBody = originalStack.split('\n').slice(1).join('\n');
143
140
- return `${currentHeader}\n${currentStack.split('\n').slice(1).join('\n')}\n\nCaused by:\n${originalStack}`;
144
+ return `${currentHeader}\n${currentStack.split('\n').slice(1).join('\n')}\n\nCaused by:\n${originalStackBody}`;
145
}
146
147
/**
@@ -191,7 +195,11 @@ export class ComposioError extends Error {
195
if (includeStack && stack) {
196
if (stack.includes('Caused by:')) {
197
const [currentStack, causeStack] = stack.split('Caused by:');
194
- data.stack = [...currentStack.split('\n').slice(1), 'Caused by:', ...causeStack.split('\n')];
198
+ data.stack = [
199
+ ...currentStack.split('\n').slice(1),
200
+ 'Caused by:',
201
+ ...causeStack.split('\n'),
202
+ ];
203
} else {
204
data.stack = stack.split('\n').slice(1);
205
}