ts/packages/core/docs/error-consistency.md
This document outlines the standardized pattern for error classes in the Composio SDK.
All error classes in the Composio SDK follow this standard pattern:
export class SomeSpecificError extends ComposioError {
constructor(
message: string = 'Default error message',
options: Omit<ComposioErrorOptions, 'code'> = {}
) {
super(message, {
...options,
code: ERROR_CODE_CONSTANT,
possibleFixes: options.possibleFixes || [
'Default fix suggestion 1',
'Default fix suggestion 2',
],
});
this.name = 'SomeSpecificError';
}
}
...options and only specific properties are overridden.possibleFixes are provided but can be overridden.name property to match the class name.Some error classes have specific requirements:
ValidationError: Accepts a zodError in the options.
new ValidationError('Message', { cause: someZodError });
ComposioToolExecutionError: Accepts an originalError in the options.
new ComposioToolExecutionError('Message', { originalError: someError });
// Basic usage
throw new ComposioNoAPIKeyError();
// With custom message
throw new ComposioToolNotFoundError('Could not find the specified tool');
// With additional options
throw new ComposioConnectedAccountNotFoundError('Account not found', {
meta: {
accountId: '12345',
userId: 'user123',
},
});
// Special cases
try {
// Some code that might throw
} catch (error) {
// Handle tool execution errors
throw new ComposioToolExecutionError('Tool failed', {
originalError: error,
meta: { toolId: 'some-tool' },
});
// Handle validation errors
throw new ValidationError('Validation failed', {
zodError: someZodError,
});
}
All error classes inherit these helpful methods from ComposioError: