10
ComposioToolExecutionRateLimitError,
11
ComposioToolFetchError,
12
ComposioToolFetchRateLimitError,
13
+ ComposioToolNotFoundError,
14
+ handleToolExecutionError,
15
isComposioRateLimitError,
16
} from '../../src/errors/ToolErrors';
17
196
expect(isComposioRateLimitError(error)).toBe(true);
197
expect(error.retryAfterSeconds).toBe(7);
198
expect(error.statusCode).toBe(429);
199
+ expect(error.message).toBe(`Rate limited while retrieving tool with slug ${SLUG}`);
200
expect(error.possibleFixes).toEqual([
201
'Wait 7 seconds, then retry',
202
'Reduce how many requests your organization sends per minute',
214
expect(isComposioRateLimitError(error)).toBe(true);
215
expect(error.retryAfterSeconds).toBe(7);
216
expect(error.statusCode).toBe(429);
217
+ expect(error.message).toBe(`Rate limited while executing the tool ${toolMocks.rawTool.slug}`);
218
expect(execute).toHaveBeenCalledTimes(1);
219
});
220
340
expect(error.possibleFixes).toEqual([SLUG_FIX]);
341
});
342
339
- it('keeps the cause of a missing connected account', async () => {
343
+ it('strips terminal escapes and line breaks from server text', async () => {
344
const { tools } = createTools({
341
- execute: () => rejected(400, { message: 'No connected account found', code: 1803 }),
345
+ execute: () =>
346
+ rejected(403, {
347
+ message: 'denied\u001b[31m\n[!] run: evil',
348
+ code: 1403,
349
+ suggested_fix: 'retry\u001b]0;owned\u0007 now',
350
+ }),
351
+ });
352
+
353
+ const error = await run(tools).catch(e => e);
354
+
355
+ expect(error.message).toBe(
356
+ `Error executing the tool ${toolMocks.rawTool.slug}: denied [!] run: evil`
357
+ );
358
+ expect(error.possibleFixes).toEqual(['retry now']);
359
+ expect(error.message).not.toMatch(/[\u0000-\u001f\u007f-\u009f]/);
360
+ });
361
+
362
+ it('keeps the original reason when the failure never reached the API', () => {
363
+ const error = handleToolExecutionError(SLUG, new Error('socket hang up\n\u001b[31m'));
364
+
365
+ expect(error.message).toBe(`Error executing the tool ${SLUG}: socket hang up`);
366
+ });
367
+
368
+ it('surfaces the server details of a rate limit', async () => {
369
+ const { tools } = createTools({
370
+ execute: () =>
371
+ rejected(
372
+ 429,
373
+ { message: 'slow down', code: 1429, suggested_fix: 'Wait an hour' },
374
+ { 'retry-after': '7' }
375
+ ),
376
+ });
377
+
378
+ const error = await run(tools).catch(e => e);
379
+
380
+ expect(error).toBeInstanceOf(ComposioToolExecutionRateLimitError);
381
+ expect(error.message).toBe(
382
+ `Rate limited while executing the tool ${toolMocks.rawTool.slug}: slow down`
383
+ );
384
+ expect(error.statusCode).toBe(429);
385
+ expect(error.apiErrorCode).toBe(1429);
386
+ expect(error.possibleFixes).toEqual(['Wait an hour']);
387
+ expect(error.retryAfterSeconds).toBe(7);
388
+ });
389
+
390
+ it('strips terminal escapes from the missing-account message', async () => {
391
+ const { tools } = createTools({
392
+ execute: () =>
393
+ rejected(400, {
394
+ message: 'No connected account\u001b[31m\n[!] connect',
395
+ code: 1803,
396
+ }),
397
+ });
398
+
399
+ const error = await run(tools).catch(e => e);
400
+
401
+ expect(error).toBeInstanceOf(ComposioConnectedAccountNotFoundError);
402
+ expect(error.message).toBe('No connected account [!] connect');
403
+ expect(error.message).not.toMatch(/[\u0000-\u001f\u007f-\u009f]/);
404
+ });
405
+
406
+ it('keeps the server status, fix and code of a missing connected account', async () => {
407
+ const { tools } = createTools({
408
+ execute: () =>
409
+ rejected(400, {
410
+ message: 'No connected account found',
411
+ code: 1803,
412
+ suggested_fix: 'Connect Gmail first',
413
+ }),
414
});
415
416
const error = await run(tools).catch(e => e);
417
418
expect(error).toBeInstanceOf(ComposioConnectedAccountNotFoundError);
419
expect(error.message).toBe('No connected account found');
348
- // The class sets its status itself, and an explicit status wins over the cause's.
349
- expect(error.statusCode).toBe(404);
420
+ expect(error.statusCode).toBe(400);
421
+ expect(error.apiErrorCode).toBe(1803);
422
+ expect(error.possibleFixes).toEqual(['Connect Gmail first']);
423
expect(error.cause).toBeInstanceOf(APIError);
424
expect(error.cause.status).toBe(400);
425
});
426
});
427
+
428
+describe('tool fetch errors', () => {
429
+ it('surfaces the server details of a 429', async () => {
430
+ const { tools } = createTools({
431
+ retrieve: () =>
432
+ json(
433
+ {
434
+ error: {
435
+ message: 'slow down',
436
+ code: 1429,
437
+ slug: 'RATE_LIMITED',
438
+ status: 429,
439
+ suggested_fix: 'Wait an hour',
440
+ },
441
+ },
442
+ 429,
443
+ { 'retry-after': '7', 'retry-after-ms': '1' }
444
+ ),
445
+ });
446
+
447
+ const error = await run(tools).catch(e => e);
448
+
449
+ expect(error).toBeInstanceOf(ComposioToolFetchRateLimitError);
450
+ expect(error.message).toBe(`Rate limited while retrieving tool with slug ${SLUG}: slow down`);
451
+ expect(error.statusCode).toBe(429);
452
+ expect(error.apiErrorCode).toBe(1429);
453
+ expect(error.possibleFixes).toEqual(['Wait an hour']);
454
+ expect(error.retryAfterSeconds).toBe(7);
455
+ });
456
+
457
+ it('surfaces the server details of a 410', async () => {
458
+ const { tools, execute } = createTools({
459
+ retrieve: () =>
460
+ json(
461
+ {
462
+ error: {
463
+ message: 'Toolkit version 20250101_00 is retired',
464
+ code: 1410,
465
+ slug: 'TOOLKIT_VERSION_RETIRED',
466
+ status: 410,
467
+ suggested_fix: 'Pin 20250909_00',
468
+ },
469
+ },
470
+ 410,
471
+ { 'x-request-id': 'req_fetch_410' }
472
+ ),
473
+ });
474
+
475
+ const error = await tools.getRawComposioToolBySlug(SLUG).catch(e => e);
476
+
477
+ expect(error).toBeInstanceOf(ComposioToolFetchError);
478
+ expect(error.message).toBe(
479
+ `Unable to retrieve tool with slug ${SLUG}: Toolkit version 20250101_00 is retired`
480
+ );
481
+ expect(error.statusCode).toBe(410);
482
+ expect(error.apiErrorCode).toBe(1410);
483
+ expect(error.requestId).toBe('req_fetch_410');
484
+ expect(error.possibleFixes).toEqual(['Pin 20250909_00']);
485
+ expect(execute).not.toHaveBeenCalled();
486
+ });
487
+
488
+ it('surfaces the server details of a 404', async () => {
489
+ const { tools } = createTools({
490
+ retrieve: () =>
491
+ json(
492
+ {
493
+ error: {
494
+ message: 'No tool with that slug in the pinned version',
495
+ code: 1404,
496
+ slug: 'TOOL_NOT_FOUND',
497
+ status: 404,
498
+ suggested_fix: 'Use the latest version',
499
+ },
500
+ },
501
+ 404
502
+ ),
503
+ });
504
+
505
+ const error = await tools.getRawComposioToolBySlug(SLUG).catch(e => e);
506
+
507
+ expect(error).toBeInstanceOf(ComposioToolNotFoundError);
508
+ expect(error.message).toBe(
509
+ `Tool with slug ${SLUG} not found: No tool with that slug in the pinned version`
510
+ );
511
+ expect(error.statusCode).toBe(404);
512
+ expect(error.apiErrorCode).toBe(1404);
513
+ expect(error.possibleFixes).toEqual(['Use the latest version']);
514
+ });
515
+});