The best way to control Claude Code, Codex and more from any computer or phone

main
ts 33 lines 1.11 KB
Raw
1 import * as Predicate from "effect/Predicate";
2
3 /**
4 * Marker for error classes whose `message` is written for end users. The CLI's
5 * top-level handler prints a marked error's `message` as a single friendly
6 * line instead of dumping the raw cause chain.
7 *
8 * Mark a class by assigning the symbol in the class body:
9 *
10 * ```ts
11 * export class MyError extends Data.TaggedError("MyError")<{
12 * readonly message: string;
13 * }> {
14 * readonly [UserFacingError] = true;
15 * }
16 * ```
17 *
18 * Classes without a human-readable `message` prop derive one with a getter
19 * (see `AlchemistNotFound` in `Alchemist/Errors.ts`).
20 */
21 export const UserFacingError: unique symbol = Symbol.for("alchemy/UserFacingError");
22
23 /** An error carrying a human-readable `message` that is safe to print as-is. */
24 export interface UserFacingError {
25 readonly [UserFacingError]: true;
26 readonly message: string;
27 }
28
29 export const isUserFacing = (error: unknown): error is UserFacingError =>
30 Predicate.hasProperty(error, UserFacingError) &&
31 error[UserFacingError] === true &&
32 Predicate.hasProperty(error, "message") &&
33 typeof error.message === "string";