@devries-cameron20 / composio Mirror · read-only
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 21, 04:45 UTC

next
ts 37 lines 1.36 KB
Raw
1 import { Predicate } from 'effect';
2
3 /**
4 * Marks an error class as an expected failure: the user fixes it by changing the invocation or
5 * their setup, or a remote service reported it clearly. the invocation (`src/invocation/invocation.ts`) prints its `message` on
6 * stderr and exits 1, with no defect banner. Anything unmarked is a defect.
7 *
8 * An error class opts in where it is defined, with a getter, so no central list needs updating:
9 *
10 * @example
11 * ```ts
12 * class MissingThingError extends Data.TaggedError('commands/MissingThingError')<{
13 * readonly message: string;
14 * }> {
15 * get [ExpectedFailure]() {
16 * return true;
17 * }
18 * }
19 * ```
20 *
21 * A getter, rather than an instance field, stays off the instance's own properties, so it does
22 * not change structural equality or serialization, and it can depend on a field, e.g. only one
23 * `reason` is expected.
24 */
25 export const ExpectedFailure: unique symbol = Symbol.for('@composio/cli/ExpectedFailure');
26
27 /** An error the invocation prints as its message alone. */
28 export interface ExpectedFailure {
29 readonly [ExpectedFailure]: boolean;
30 readonly message: string;
31 }
32
33 export const isExpectedFailure = (error: unknown): error is ExpectedFailure =>
34 Predicate.hasProperty(error, ExpectedFailure) &&
35 error[ExpectedFailure] === true &&
36 Predicate.hasProperty(error, 'message') &&
37 Predicate.isString(error.message);