ChatError unstable
The error every chat operation fails with.
A ChatError records the platform and op, and holds one of twelve reasons.
Each reason has a three-way retry value: retry means nothing happened and
the request is safe to send again, uncertain means a write may or may not
have landed, and denied means sending again gives the same answer.
Details
detailis redacted: a platform code such aschannel_not_found, never message text, file names or ids.file_refusedis fixed by the core: on adeniedreason it promises a file was refused and nothing is left posted. It overrides platform error names; the original code stays oncause.causeis the error underneath (an HTTP error, a client library error, aSchemaError). It is unredacted and can hold URLs, ids and payload values. Schema encoding keeps it andtoJSONleaves it out, so logging an error does not print it.
Constants
fileRefused
unstableDetail for a refused file on any denied reason: nothing is left posted.
Signature
declare const fileRefused: "file_refused"interactionExpired
unstableDetail for a modal returned after the deadline: the reason is NotFound
and the op openModal.
Signature
declare const interactionExpired: "interaction_expired"Errors
The error every chat operation fails with.
Details
opis the operation that failed:post,edit,historyand so on.causeis the reason, so a failed span's stack trace carries the whole chain: theChatError, the reason and the error under it.retryandretryAfterdelegate to the reason.messageis built from the platform, op, reason anddetail, never from the cause.
Signature
declare class ChatError extends { readonly _tag: "ChatError"; readonly op: string; readonly platform: string; readonly reason: RateLimited | Unsupported | Transport | PlatformUnavailable | NoAdapter | Unauthenticated | Forbidden | NotFound | TooLarge | InvalidRequest | InvalidResponse | Unknown;} & YieldableError<this> { constructor(...args: [props: { readonly _tag?: "ChatError"; readonly op: string; readonly platform: string; readonly reason: RateLimited | Unsupported | Transport | PlatformUnavailable | NoAdapter | Unauthenticated | Forbidden | NotFound | TooLarge | InvalidRequest | InvalidResponse | Unknown; }, options?: MakeOptions]); readonly "~effect/chat/ChatError": "~effect/chat/ChatError"; readonly cause: RateLimited | Unsupported | Transport | PlatformUnavailable | NoAdapter | Unauthenticated | Forbidden | NotFound | TooLarge | InvalidRequest | InvalidResponse | Unknown; message: string; retry: "retry" | "uncertain" | "denied"; retryAfter: Duration | undefined; toJSON(): unknown;}Example Matching on a reason
import { Effect } from "effect"import { ChatError } from "effect/chat"
const failing = Effect.fail( new ChatError.ChatError({ platform: "slack", op: "post", reason: new ChatError.NotFound({ detail: "channel_not_found" }) }))
const program = failing.pipe( Effect.catchReason("ChatError", "NotFound", (reason) => Effect.succeed(reason.detail)))
await Effect.runPromise(program) // => "channel_not_found"One of the twelve reasons a ChatError holds.
Signature
type ChatErrorReason = RateLimited | Unsupported | Transport | PlatformUnavailable | NoAdapter | Unauthenticated | Forbidden | NotFound | TooLarge | InvalidRequest | InvalidResponse | UnknownReason for a ChatError: the platform refused the request: a missing scope, not in the channel, an archived thread.
Details
Retry value denied.
Signature
declare class Forbidden extends { readonly _tag: "Forbidden"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "Forbidden"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}InvalidRequest
unstableReason for an ChatError: the platform refused the request as malformed.
Details
Retry value denied.
Signature
declare class InvalidRequest extends { readonly _tag: "InvalidRequest"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "InvalidRequest"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}InvalidResponse
unstableReason for an ChatError: the platform answered with something the adapter cannot decode.
Details
Retry value denied.
Signature
declare class InvalidResponse extends { readonly _tag: "InvalidResponse"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "InvalidResponse"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}Reason for a ChatError: no adapter is registered for the address's platform.
Details
Retry value denied.
Signature
declare class NoAdapter extends { readonly _tag: "NoAdapter"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "NoAdapter"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}Reason for a ChatError: the thread, message, user or attachment is gone.
Details
Retry value denied.
Signature
declare class NotFound extends { readonly _tag: "NotFound"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "NotFound"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}RateLimited
unstableReason for a ChatError: the platform rate limited the request.
Details
Retry value retry: nothing happened. retryAfter is the wait the platform asked for, when it gave one.
Signature
declare class RateLimited extends { readonly _tag: "RateLimited"; cause?: unknown; detail?: string; readonly retryAfter?: Duration;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "RateLimited"; cause?: unknown; detail?: string; readonly retryAfter?: Duration; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}Reason for a ChatError: the request is past a size limit: message length, file size or download's maxBytes.
Details
- Retry value
denied. subjectsays what was too large, when the adapter can tell:textfor the message text,filesfor the files sent with it. An adapter sets it on every refusal ofpost,editandNativeStreamit can attribute.- Usually raised before the call. A platform-side size refusal carries
the platform's error name in
detail, unless a file was refused: then it isfile_refused.ChatMarkdownkeys its fallback on that detail, not onsubject.
Signature
declare class TooLarge extends { readonly _tag: "TooLarge"; cause?: unknown; detail?: string; readonly subject?: "text" | "files";} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "TooLarge"; cause?: unknown; detail?: string; readonly subject?: "text" | "files"; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}Reason for a ChatError: the request failed in transport.
Details
Retry value retry when the request never left, uncertain when it did and no answer came.
Signature
declare class Transport extends { readonly _tag: "Transport"; cause?: unknown; detail?: string; readonly retry: "retry" | "uncertain" | "denied";} & YieldableError<this> { constructor(...args: [props: { readonly _tag?: "Transport"; cause?: unknown; detail?: string; readonly retry: "retry" | "uncertain" | "denied"; }, options?: MakeOptions]); message: string; toJSON(): unknown;}Unauthenticated
unstableReason for an ChatError: the platform refused the credentials: a bad or revoked token.
Details
Retry value denied.
Signature
declare class Unauthenticated extends { readonly _tag: "Unauthenticated"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "Unauthenticated"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}Reason for an ChatError: the request failed for a reason the adapter cannot classify.
Details
Retry value uncertain: a write may or may not have landed.
Signature
declare class Unknown extends { readonly _tag: "Unknown"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props?: { readonly _tag?: "Unknown"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}Unsupported
unstableReason for an ChatError: the platform has no equivalent for the op.
Details
Retry value denied. Every op exists on every platform and fails with this where the platform has no equivalent; capability names what is missing.
Signature
declare class Unsupported extends { readonly _tag: "Unsupported"; readonly capability: "getUser" | "edit" | "delete" | "fetchMessage" | "history" | "download" | "startThread" | "getThread" | "opener" | "files" | "replyTo" | "nativeStream" | "buttons" | "selects" | "modals" | "modalErrors" | "commands" | "ephemeral"; cause?: unknown; detail?: string;} & YieldableError<this> { constructor(...args: [props: { readonly _tag?: "Unsupported"; readonly capability: "getUser" | "edit" | "delete" | "fetchMessage" | "history" | "download" | "startThread" | "getThread" | "opener" | "files" | "replyTo" | "nativeStream" | "buttons" | "selects" | "modals" | "modalErrors" | "commands" | "ephemeral"; cause?: unknown; detail?: string; }, options?: MakeOptions]); message: string; retry: "retry" | "uncertain" | "denied"; toJSON(): unknown;}Guards
isChatError
unstableReturns whether a value is a ChatError.
Signature
declare function isChatError(u: unknown): u is ChatErrorModels
A capability name from ChatAdapter.Descriptor.
Signature
type Capability = typeof Capability.TypeThe retry value of a chat error.
Signature
type Retry = typeof Retry.TypeSchemas
Capability
unstableSchema for a capability name from ChatAdapter.Descriptor.
Details
buttonscovers buttons and link buttons,selectsselects on a message, andmodalsopening a modal from a click or a command.modalErrorsis field errors put back into an open modal. A platform without it answerserrorssome other way, so no op fails for it.commandsis slash commands arriving, andfollowUpworking.ephemeralis a command's answer that only the person who ran it sees. A platform withcommandsand without it refuses a private answer.
Signature
declare const Capability: Literals<readonly ["edit", "delete", "fetchMessage", "history", "download", "files", "replyTo", "startThread", "getThread", "opener", "getUser", "nativeStream", "buttons", "selects", "modals", "modalErrors", "commands", "ephemeral"]>ChatErrorReason
unstableSchema for the twelve reasons a ChatError holds.
Signature
declare const ChatErrorReason: Union<[typeof RateLimited, typeof Unsupported, typeof Transport, typeof PlatformUnavailable, typeof NoAdapter, typeof Unauthenticated, typeof Forbidden, typeof NotFound]>Schema for the retry value of a chat error.
Details
retry: nothing happened, safe to send again.uncertain: the write may or may not have landed. Adapters never retry it.denied: sending again gives the same answer.
Signature
declare const Retry: Literals<readonly ["retry", "uncertain", "denied"]>