Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { Data, Runtime } from 'effect'; |
| 2 | import { commandInputError } from 'src/commands/errors'; |
| 3 | import { ExpectedFailure } from 'src/effects/expected-failure'; |
| 4 | import { TEMPORARY_FAILURE_EXIT_CODE } from 'src/effects/retry-advice'; |
| 5 | |
| 6 | // Also raised by the hand-rolled `--parallel` mini-parser (`parseParallelExecuteArgs` in `tools.execute.parallel.ts`). |
| 7 | export const invalidArguments = commandInputError('execute'); |
| 8 | |
| 9 | // The reasons below are the ones this command constructs each error with; TypeScript cannot infer a |
| 10 | // union from scattered constructor calls, so a new reason is added here next to its first use. |
| 11 | |
| 12 | /** |
| 13 | * `composio execute` cannot run the tool as invoked: a `--file` the tool cannot take, or (with |
| 14 | * `--parallel`) a toolkit the user has not connected. An expected failure: the invocation prints |
| 15 | * the message and exits 1. |
| 16 | */ |
| 17 | export class ToolExecutionError extends Data.TaggedError('ToolExecutionError')<{ |
| 18 | readonly reason: 'file_input' | 'connection_check'; |
| 19 | readonly message: string; |
| 20 | readonly toolSlug?: string; |
| 21 | }> { |
| 22 | get [ExpectedFailure]() { |
| 23 | return true; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * A failed execution whose result is already on stdout as `{ "successful": false, ... }`. |
| 29 | * The runtime prints nothing more for it (`[Runtime.errorReported]` is false) and exits 1, or |
| 30 | * `TEMPORARY_FAILURE_EXIT_CODE` (75) when it is `retryable`: running the same command again |
| 31 | * cannot make a change twice (see `src/effects/retry-advice.ts`). |
| 32 | */ |
| 33 | export class ReportedToolExecutionError extends Data.TaggedError('ReportedToolExecutionError')<{ |
| 34 | readonly reason: 'connection_check' | 'execution_failed' | 'parallel_failed'; |
| 35 | readonly message: string; |
| 36 | readonly toolSlug?: string; |
| 37 | readonly retryable?: boolean; |
| 38 | }> { |
| 39 | get [Runtime.errorReported]() { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | get [Runtime.errorExitCode]() { |
| 44 | return this.retryable === true ? TEMPORARY_FAILURE_EXIT_CODE : 1; |
| 45 | } |
| 46 | } |