Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Errors.ts

163 lines4.6 KB

1import { Schema } from "effect";
2​
3import type { CheckpointServiceError } from "../checkpointing/Errors.ts";
4​
5/**
6 * ProviderAdapterValidationError - Invalid adapter API input.
7 */
8export class ProviderAdapterValidationError extends Schema.TaggedErrorClass<ProviderAdapterValidationError>()(
9 "ProviderAdapterValidationError",
10 {
11 provider: Schema.String,
12 operation: Schema.String,
13 issue: Schema.String,
14 cause: Schema.optional(Schema.Defect),
15 },
16) {
17 override get message(): string {
18 return `Provider adapter validation failed (${this.provider}) in ${this.operation}: ${this.issue}`;
19 }
21​
22/**
23 * ProviderAdapterSessionNotFoundError - Adapter-owned session id is unknown.
24 */
25export class ProviderAdapterSessionNotFoundError extends Schema.TaggedErrorClass<ProviderAdapterSessionNotFoundError>()(
26 "ProviderAdapterSessionNotFoundError",
27 {
28 provider: Schema.String,
29 threadId: Schema.String,
30 cause: Schema.optional(Schema.Defect),
31 },
32) {
33 override get message(): string {
34 return `Unknown ${this.provider} adapter thread: ${this.threadId}`;
35 }
37​
38/**
39 * ProviderAdapterSessionClosedError - Adapter session exists but is closed.
40 */
41export class ProviderAdapterSessionClosedError extends Schema.TaggedErrorClass<ProviderAdapterSessionClosedError>()(
42 "ProviderAdapterSessionClosedError",
43 {
44 provider: Schema.String,
45 threadId: Schema.String,
46 cause: Schema.optional(Schema.Defect),
47 },
48) {
49 override get message(): string {
50 return `${this.provider} adapter thread is closed: ${this.threadId}`;
51 }
53​
54/**
55 * ProviderAdapterRequestError - Provider protocol request failed or timed out.
56 */
57export class ProviderAdapterRequestError extends Schema.TaggedErrorClass<ProviderAdapterRequestError>()(
58 "ProviderAdapterRequestError",
59 {
60 provider: Schema.String,
61 method: Schema.String,
62 detail: Schema.String,
63 cause: Schema.optional(Schema.Defect),
64 },
65) {
66 override get message(): string {
67 return `Provider adapter request failed (${this.provider}) for ${this.method}: ${this.detail}`;
68 }
70​
71/**
72 * ProviderAdapterProcessError - Provider process lifecycle failure.
73 */
74export class ProviderAdapterProcessError extends Schema.TaggedErrorClass<ProviderAdapterProcessError>()(
75 "ProviderAdapterProcessError",
76 {
77 provider: Schema.String,
78 threadId: Schema.String,
79 detail: Schema.String,
80 cause: Schema.optional(Schema.Defect),
81 },
82) {
83 override get message(): string {
84 return `Provider adapter process error (${this.provider}) for thread ${this.threadId}: ${this.detail}`;
85 }
87​
88/**
89 * ProviderValidationError - Invalid provider API input.
90 */
91export class ProviderValidationError extends Schema.TaggedErrorClass<ProviderValidationError>()(
92 "ProviderValidationError",
93 {
94 operation: Schema.String,
95 issue: Schema.String,
96 cause: Schema.optional(Schema.Defect),
97 },
98) {
99 override get message(): string {
100 return `Provider validation failed in ${this.operation}: ${this.issue}`;
101 }
103​
104/**
105 * ProviderUnsupportedError - Requested provider is not implemented.
106 */
107export class ProviderUnsupportedError extends Schema.TaggedErrorClass<ProviderUnsupportedError>()(
108 "ProviderUnsupportedError",
109 {
110 provider: Schema.String,
111 cause: Schema.optional(Schema.Defect),
112 },
113) {
114 override get message(): string {
115 return `Provider '${this.provider}' is not implemented`;
116 }
118​
119/**
120 * ProviderSessionNotFoundError - Provider-facing session not found.
121 */
122export class ProviderSessionNotFoundError extends Schema.TaggedErrorClass<ProviderSessionNotFoundError>()(
123 "ProviderSessionNotFoundError",
124 {
125 threadId: Schema.String,
126 cause: Schema.optional(Schema.Defect),
127 },
128) {
129 override get message(): string {
130 return `Unknown provider thread: ${this.threadId}`;
131 }
133​
134/**
135 * ProviderSessionDirectoryPersistenceError - Session directory persistence failure.
136 */
137export class ProviderSessionDirectoryPersistenceError extends Schema.TaggedErrorClass<ProviderSessionDirectoryPersistenceError>()(
138 "ProviderSessionDirectoryPersistenceError",
139 {
140 operation: Schema.String,
141 detail: Schema.String,
142 cause: Schema.optional(Schema.Defect),
143 },
144) {
145 override get message(): string {
146 return `Provider session directory persistence error in ${this.operation}: ${this.detail}`;
147 }
149​
150export type ProviderAdapterError =
151 | ProviderAdapterValidationError
152 | ProviderAdapterSessionNotFoundError
153 | ProviderAdapterSessionClosedError
154 | ProviderAdapterRequestError
155 | ProviderAdapterProcessError;
156​
157export type ProviderServiceError =
158 | ProviderValidationError
159 | ProviderUnsupportedError
160 | ProviderSessionNotFoundError
161 | ProviderSessionDirectoryPersistenceError
162 | ProviderAdapterError
163 | CheckpointServiceError;