@rivetkit/effect 0.0.0-codex-rivetkit-cli-preview.5e414a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Action.d.ts +104 -0
- package/dist/Action.d.ts.map +1 -0
- package/dist/Action.js +50 -0
- package/dist/Action.js.map +1 -0
- package/dist/Actor.d.ts +133 -0
- package/dist/Actor.d.ts.map +1 -0
- package/dist/Actor.js +104 -0
- package/dist/Actor.js.map +1 -0
- package/dist/Client.d.ts +31 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +98 -0
- package/dist/Client.js.map +1 -0
- package/dist/Logger.d.ts +29 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/Logger.js +31 -0
- package/dist/Logger.js.map +1 -0
- package/dist/Registry.d.ts +72 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +125 -0
- package/dist/Registry.js.map +1 -0
- package/dist/RivetError.d.ts +438 -0
- package/dist/RivetError.d.ts.map +1 -0
- package/dist/RivetError.js +873 -0
- package/dist/RivetError.js.map +1 -0
- package/dist/State.d.ts +123 -0
- package/dist/State.d.ts.map +1 -0
- package/dist/State.js +104 -0
- package/dist/State.js.map +1 -0
- package/dist/internal/ActionDispatcher.d.ts +14 -0
- package/dist/internal/ActionDispatcher.d.ts.map +1 -0
- package/dist/internal/ActionDispatcher.js +100 -0
- package/dist/internal/ActionDispatcher.js.map +1 -0
- package/dist/internal/ActionErrorEnvelope.d.ts +11 -0
- package/dist/internal/ActionErrorEnvelope.d.ts.map +1 -0
- package/dist/internal/ActionErrorEnvelope.js +14 -0
- package/dist/internal/ActionErrorEnvelope.js.map +1 -0
- package/dist/internal/ActorInstanceManager.d.ts +28 -0
- package/dist/internal/ActorInstanceManager.d.ts.map +1 -0
- package/dist/internal/ActorInstanceManager.js +51 -0
- package/dist/internal/ActorInstanceManager.js.map +1 -0
- package/dist/internal/ActorStateAdapter.d.ts +18 -0
- package/dist/internal/ActorStateAdapter.d.ts.map +1 -0
- package/dist/internal/ActorStateAdapter.js +29 -0
- package/dist/internal/ActorStateAdapter.js.map +1 -0
- package/dist/internal/StateOptions.d.ts +12 -0
- package/dist/internal/StateOptions.d.ts.map +1 -0
- package/dist/internal/StateOptions.js +2 -0
- package/dist/internal/StateOptions.js.map +1 -0
- package/dist/internal/logging.d.ts +23 -0
- package/dist/internal/logging.d.ts.map +1 -0
- package/dist/internal/logging.js +162 -0
- package/dist/internal/logging.js.map +1 -0
- package/dist/internal/tracing.d.ts +23 -0
- package/dist/internal/tracing.d.ts.map +1 -0
- package/dist/internal/tracing.js +30 -0
- package/dist/internal/tracing.js.map +1 -0
- package/dist/internal/utils.d.ts +7 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +7 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/mod.d.ts +8 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +8 -0
- package/dist/mod.js.map +1 -0
- package/package.json +46 -0
- package/src/Action.ts +231 -0
- package/src/Actor.test-d.ts +603 -0
- package/src/Actor.test.ts +206 -0
- package/src/Actor.ts +550 -0
- package/src/Client.test.ts +210 -0
- package/src/Client.ts +216 -0
- package/src/Logger.ts +43 -0
- package/src/Registry.test-d.ts +126 -0
- package/src/Registry.test.ts +411 -0
- package/src/Registry.ts +243 -0
- package/src/RivetError.test.ts +188 -0
- package/src/RivetError.ts +1044 -0
- package/src/State.test.ts +181 -0
- package/src/State.ts +224 -0
- package/src/internal/ActionDispatcher.ts +192 -0
- package/src/internal/ActionErrorEnvelope.ts +19 -0
- package/src/internal/ActorInstanceManager.ts +143 -0
- package/src/internal/ActorStateAdapter.ts +88 -0
- package/src/internal/StateOptions.ts +17 -0
- package/src/internal/logging.test.ts +288 -0
- package/src/internal/logging.ts +237 -0
- package/src/internal/tracing.ts +42 -0
- package/src/internal/utils.ts +12 -0
- package/src/mod.ts +7 -0
|
@@ -0,0 +1,1044 @@
|
|
|
1
|
+
import { Duration, Option, Predicate, Record, Schema } from "effect";
|
|
2
|
+
import * as RivetkitErrors from "rivetkit/errors";
|
|
3
|
+
|
|
4
|
+
const ReasonTypeId = "~@rivetkit/effect/RivetError/Reason" as const;
|
|
5
|
+
const TypeId = "~@rivetkit/effect/RivetError" as const;
|
|
6
|
+
|
|
7
|
+
export class Forbidden extends Schema.TaggedErrorClass<Forbidden>(
|
|
8
|
+
`${ReasonTypeId}/Forbidden`,
|
|
9
|
+
)("Forbidden", {
|
|
10
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
11
|
+
}) {
|
|
12
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
13
|
+
override get message() {
|
|
14
|
+
return this.cause.message;
|
|
15
|
+
}
|
|
16
|
+
get group() {
|
|
17
|
+
return this.cause.group;
|
|
18
|
+
}
|
|
19
|
+
get code() {
|
|
20
|
+
return this.cause.code;
|
|
21
|
+
}
|
|
22
|
+
get metadata() {
|
|
23
|
+
return this.cause.metadata;
|
|
24
|
+
}
|
|
25
|
+
get actor() {
|
|
26
|
+
return this.cause.actor;
|
|
27
|
+
}
|
|
28
|
+
get statusCode() {
|
|
29
|
+
return this.cause.statusCode;
|
|
30
|
+
}
|
|
31
|
+
get public() {
|
|
32
|
+
return this.cause.public;
|
|
33
|
+
}
|
|
34
|
+
get isRetryable(): boolean {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class ActorNotFound extends Schema.TaggedErrorClass<ActorNotFound>(
|
|
40
|
+
`${ReasonTypeId}/ActorNotFound`,
|
|
41
|
+
)("ActorNotFound", {
|
|
42
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
43
|
+
}) {
|
|
44
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
45
|
+
override get message() {
|
|
46
|
+
return this.cause.message;
|
|
47
|
+
}
|
|
48
|
+
get group() {
|
|
49
|
+
return this.cause.group;
|
|
50
|
+
}
|
|
51
|
+
get code() {
|
|
52
|
+
return this.cause.code;
|
|
53
|
+
}
|
|
54
|
+
get metadata() {
|
|
55
|
+
return this.cause.metadata;
|
|
56
|
+
}
|
|
57
|
+
get actor() {
|
|
58
|
+
return this.cause.actor;
|
|
59
|
+
}
|
|
60
|
+
get statusCode() {
|
|
61
|
+
return this.cause.statusCode;
|
|
62
|
+
}
|
|
63
|
+
get public() {
|
|
64
|
+
return this.cause.public;
|
|
65
|
+
}
|
|
66
|
+
get isRetryable(): boolean {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export class ActorStopping extends Schema.TaggedErrorClass<ActorStopping>(
|
|
72
|
+
`${ReasonTypeId}/ActorStopping`,
|
|
73
|
+
)("ActorStopping", {
|
|
74
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
75
|
+
}) {
|
|
76
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
77
|
+
override get message() {
|
|
78
|
+
return this.cause.message;
|
|
79
|
+
}
|
|
80
|
+
get group() {
|
|
81
|
+
return this.cause.group;
|
|
82
|
+
}
|
|
83
|
+
get code() {
|
|
84
|
+
return this.cause.code;
|
|
85
|
+
}
|
|
86
|
+
get metadata() {
|
|
87
|
+
return this.cause.metadata;
|
|
88
|
+
}
|
|
89
|
+
get actor() {
|
|
90
|
+
return this.cause.actor;
|
|
91
|
+
}
|
|
92
|
+
get statusCode() {
|
|
93
|
+
return this.cause.statusCode;
|
|
94
|
+
}
|
|
95
|
+
get public() {
|
|
96
|
+
return this.cause.public;
|
|
97
|
+
}
|
|
98
|
+
get isRetryable(): boolean {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class ActorRestarting extends Schema.TaggedErrorClass<ActorRestarting>(
|
|
104
|
+
`${ReasonTypeId}/ActorRestarting`,
|
|
105
|
+
)("ActorRestarting", {
|
|
106
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
107
|
+
}) {
|
|
108
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
109
|
+
override get message() {
|
|
110
|
+
return this.cause.message;
|
|
111
|
+
}
|
|
112
|
+
get group() {
|
|
113
|
+
return this.cause.group;
|
|
114
|
+
}
|
|
115
|
+
get code() {
|
|
116
|
+
return this.cause.code;
|
|
117
|
+
}
|
|
118
|
+
get metadata() {
|
|
119
|
+
return this.cause.metadata;
|
|
120
|
+
}
|
|
121
|
+
get actor() {
|
|
122
|
+
return this.cause.actor;
|
|
123
|
+
}
|
|
124
|
+
get statusCode() {
|
|
125
|
+
return this.cause.statusCode;
|
|
126
|
+
}
|
|
127
|
+
get public() {
|
|
128
|
+
return this.cause.public;
|
|
129
|
+
}
|
|
130
|
+
get isRetryable(): boolean {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
get retryAfter(): Duration.Duration | undefined {
|
|
134
|
+
if (!Predicate.isReadonlyObject(this.metadata)) return undefined;
|
|
135
|
+
return Record.get(this.metadata, "retryAfterMs").pipe(
|
|
136
|
+
Option.filter(Predicate.isNumber),
|
|
137
|
+
Option.map(Duration.millis),
|
|
138
|
+
Option.getOrUndefined,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export class ActionNotFound extends Schema.TaggedErrorClass<ActionNotFound>(
|
|
144
|
+
`${ReasonTypeId}/ActionNotFound`,
|
|
145
|
+
)("ActionNotFound", {
|
|
146
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
147
|
+
}) {
|
|
148
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
149
|
+
override get message() {
|
|
150
|
+
return this.cause.message;
|
|
151
|
+
}
|
|
152
|
+
get group() {
|
|
153
|
+
return this.cause.group;
|
|
154
|
+
}
|
|
155
|
+
get code() {
|
|
156
|
+
return this.cause.code;
|
|
157
|
+
}
|
|
158
|
+
get metadata() {
|
|
159
|
+
return this.cause.metadata;
|
|
160
|
+
}
|
|
161
|
+
get actor() {
|
|
162
|
+
return this.cause.actor;
|
|
163
|
+
}
|
|
164
|
+
get statusCode() {
|
|
165
|
+
return this.cause.statusCode;
|
|
166
|
+
}
|
|
167
|
+
get public() {
|
|
168
|
+
return this.cause.public;
|
|
169
|
+
}
|
|
170
|
+
get isRetryable(): boolean {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export class ActionTimedOut extends Schema.TaggedErrorClass<ActionTimedOut>(
|
|
176
|
+
`${ReasonTypeId}/ActionTimedOut`,
|
|
177
|
+
)("ActionTimedOut", { cause: Schema.instanceOf(RivetkitErrors.RivetError) }) {
|
|
178
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
179
|
+
override get message() {
|
|
180
|
+
return this.cause.message;
|
|
181
|
+
}
|
|
182
|
+
get group() {
|
|
183
|
+
return this.cause.group;
|
|
184
|
+
}
|
|
185
|
+
get code() {
|
|
186
|
+
return this.cause.code;
|
|
187
|
+
}
|
|
188
|
+
get metadata() {
|
|
189
|
+
return this.cause.metadata;
|
|
190
|
+
}
|
|
191
|
+
get actor() {
|
|
192
|
+
return this.cause.actor;
|
|
193
|
+
}
|
|
194
|
+
get statusCode() {
|
|
195
|
+
return this.cause.statusCode;
|
|
196
|
+
}
|
|
197
|
+
get public() {
|
|
198
|
+
return this.cause.public;
|
|
199
|
+
}
|
|
200
|
+
get isRetryable(): boolean {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export class ActionAborted extends Schema.TaggedErrorClass<ActionAborted>(
|
|
206
|
+
`${ReasonTypeId}/ActionAborted`,
|
|
207
|
+
)("ActionAborted", {
|
|
208
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
209
|
+
}) {
|
|
210
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
211
|
+
override get message() {
|
|
212
|
+
return this.cause.message;
|
|
213
|
+
}
|
|
214
|
+
get group() {
|
|
215
|
+
return this.cause.group;
|
|
216
|
+
}
|
|
217
|
+
get code() {
|
|
218
|
+
return this.cause.code;
|
|
219
|
+
}
|
|
220
|
+
get metadata() {
|
|
221
|
+
return this.cause.metadata;
|
|
222
|
+
}
|
|
223
|
+
get actor() {
|
|
224
|
+
return this.cause.actor;
|
|
225
|
+
}
|
|
226
|
+
get statusCode() {
|
|
227
|
+
return this.cause.statusCode;
|
|
228
|
+
}
|
|
229
|
+
get public() {
|
|
230
|
+
return this.cause.public;
|
|
231
|
+
}
|
|
232
|
+
get isRetryable(): boolean {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export class ActorOverloaded extends Schema.TaggedErrorClass<ActorOverloaded>(
|
|
238
|
+
`${ReasonTypeId}/ActorOverloaded`,
|
|
239
|
+
)("ActorOverloaded", {
|
|
240
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
241
|
+
}) {
|
|
242
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
243
|
+
override get message() {
|
|
244
|
+
return this.cause.message;
|
|
245
|
+
}
|
|
246
|
+
get group() {
|
|
247
|
+
return this.cause.group;
|
|
248
|
+
}
|
|
249
|
+
get code() {
|
|
250
|
+
return this.cause.code;
|
|
251
|
+
}
|
|
252
|
+
get metadata() {
|
|
253
|
+
return this.cause.metadata;
|
|
254
|
+
}
|
|
255
|
+
get actor() {
|
|
256
|
+
return this.cause.actor;
|
|
257
|
+
}
|
|
258
|
+
get statusCode() {
|
|
259
|
+
return this.cause.statusCode;
|
|
260
|
+
}
|
|
261
|
+
get public() {
|
|
262
|
+
return this.cause.public;
|
|
263
|
+
}
|
|
264
|
+
get isRetryable(): boolean {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export class IncomingMessageTooLong extends Schema.TaggedErrorClass<IncomingMessageTooLong>(
|
|
270
|
+
`${ReasonTypeId}/IncomingMessageTooLong`,
|
|
271
|
+
)("IncomingMessageTooLong", {
|
|
272
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
273
|
+
}) {
|
|
274
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
275
|
+
override get message() {
|
|
276
|
+
return this.cause.message;
|
|
277
|
+
}
|
|
278
|
+
get group() {
|
|
279
|
+
return this.cause.group;
|
|
280
|
+
}
|
|
281
|
+
get code() {
|
|
282
|
+
return this.cause.code;
|
|
283
|
+
}
|
|
284
|
+
get metadata() {
|
|
285
|
+
return this.cause.metadata;
|
|
286
|
+
}
|
|
287
|
+
get actor() {
|
|
288
|
+
return this.cause.actor;
|
|
289
|
+
}
|
|
290
|
+
get statusCode() {
|
|
291
|
+
return this.cause.statusCode;
|
|
292
|
+
}
|
|
293
|
+
get public() {
|
|
294
|
+
return this.cause.public;
|
|
295
|
+
}
|
|
296
|
+
get isRetryable(): boolean {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export class OutgoingMessageTooLong extends Schema.TaggedErrorClass<OutgoingMessageTooLong>(
|
|
302
|
+
`${ReasonTypeId}/OutgoingMessageTooLong`,
|
|
303
|
+
)("OutgoingMessageTooLong", {
|
|
304
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
305
|
+
}) {
|
|
306
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
307
|
+
override get message() {
|
|
308
|
+
return this.cause.message;
|
|
309
|
+
}
|
|
310
|
+
get group() {
|
|
311
|
+
return this.cause.group;
|
|
312
|
+
}
|
|
313
|
+
get code() {
|
|
314
|
+
return this.cause.code;
|
|
315
|
+
}
|
|
316
|
+
get metadata() {
|
|
317
|
+
return this.cause.metadata;
|
|
318
|
+
}
|
|
319
|
+
get actor() {
|
|
320
|
+
return this.cause.actor;
|
|
321
|
+
}
|
|
322
|
+
get statusCode() {
|
|
323
|
+
return this.cause.statusCode;
|
|
324
|
+
}
|
|
325
|
+
get public() {
|
|
326
|
+
return this.cause.public;
|
|
327
|
+
}
|
|
328
|
+
get isRetryable(): boolean {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export class InvalidEncoding extends Schema.TaggedErrorClass<InvalidEncoding>(
|
|
334
|
+
`${ReasonTypeId}/InvalidEncoding`,
|
|
335
|
+
)("InvalidEncoding", {
|
|
336
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
337
|
+
}) {
|
|
338
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
339
|
+
override get message() {
|
|
340
|
+
return this.cause.message;
|
|
341
|
+
}
|
|
342
|
+
get group() {
|
|
343
|
+
return this.cause.group;
|
|
344
|
+
}
|
|
345
|
+
get code() {
|
|
346
|
+
return this.cause.code;
|
|
347
|
+
}
|
|
348
|
+
get metadata() {
|
|
349
|
+
return this.cause.metadata;
|
|
350
|
+
}
|
|
351
|
+
get actor() {
|
|
352
|
+
return this.cause.actor;
|
|
353
|
+
}
|
|
354
|
+
get statusCode() {
|
|
355
|
+
return this.cause.statusCode;
|
|
356
|
+
}
|
|
357
|
+
get public() {
|
|
358
|
+
return this.cause.public;
|
|
359
|
+
}
|
|
360
|
+
get isRetryable(): boolean {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export class InvalidRequest extends Schema.TaggedErrorClass<InvalidRequest>(
|
|
366
|
+
`${ReasonTypeId}/InvalidRequest`,
|
|
367
|
+
)("InvalidRequest", {
|
|
368
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
369
|
+
}) {
|
|
370
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
371
|
+
override get message() {
|
|
372
|
+
return this.cause.message;
|
|
373
|
+
}
|
|
374
|
+
get group() {
|
|
375
|
+
return this.cause.group;
|
|
376
|
+
}
|
|
377
|
+
get code() {
|
|
378
|
+
return this.cause.code;
|
|
379
|
+
}
|
|
380
|
+
get metadata() {
|
|
381
|
+
return this.cause.metadata;
|
|
382
|
+
}
|
|
383
|
+
get actor() {
|
|
384
|
+
return this.cause.actor;
|
|
385
|
+
}
|
|
386
|
+
get statusCode() {
|
|
387
|
+
return this.cause.statusCode;
|
|
388
|
+
}
|
|
389
|
+
get public() {
|
|
390
|
+
return this.cause.public;
|
|
391
|
+
}
|
|
392
|
+
get isRetryable(): boolean {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export class GuardActorReadyTimeout extends Schema.TaggedErrorClass<GuardActorReadyTimeout>(
|
|
398
|
+
`${ReasonTypeId}/GuardActorReadyTimeout`,
|
|
399
|
+
)("GuardActorReadyTimeout", {
|
|
400
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
401
|
+
}) {
|
|
402
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
403
|
+
override get message() {
|
|
404
|
+
return this.cause.message;
|
|
405
|
+
}
|
|
406
|
+
get group() {
|
|
407
|
+
return this.cause.group;
|
|
408
|
+
}
|
|
409
|
+
get code() {
|
|
410
|
+
return this.cause.code;
|
|
411
|
+
}
|
|
412
|
+
get metadata() {
|
|
413
|
+
return this.cause.metadata;
|
|
414
|
+
}
|
|
415
|
+
get actor() {
|
|
416
|
+
return this.cause.actor;
|
|
417
|
+
}
|
|
418
|
+
get statusCode() {
|
|
419
|
+
return this.cause.statusCode;
|
|
420
|
+
}
|
|
421
|
+
get public() {
|
|
422
|
+
return this.cause.public;
|
|
423
|
+
}
|
|
424
|
+
get isRetryable(): boolean {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export class GuardActorRunnerFailed extends Schema.TaggedErrorClass<GuardActorRunnerFailed>(
|
|
430
|
+
`${ReasonTypeId}/GuardActorRunnerFailed`,
|
|
431
|
+
)("GuardActorRunnerFailed", {
|
|
432
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
433
|
+
}) {
|
|
434
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
435
|
+
override get message() {
|
|
436
|
+
return this.cause.message;
|
|
437
|
+
}
|
|
438
|
+
get group() {
|
|
439
|
+
return this.cause.group;
|
|
440
|
+
}
|
|
441
|
+
get code() {
|
|
442
|
+
return this.cause.code;
|
|
443
|
+
}
|
|
444
|
+
get metadata() {
|
|
445
|
+
return this.cause.metadata;
|
|
446
|
+
}
|
|
447
|
+
get actor() {
|
|
448
|
+
return this.cause.actor;
|
|
449
|
+
}
|
|
450
|
+
get statusCode() {
|
|
451
|
+
return this.cause.statusCode;
|
|
452
|
+
}
|
|
453
|
+
get public() {
|
|
454
|
+
return this.cause.public;
|
|
455
|
+
}
|
|
456
|
+
get isRetryable(): boolean {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export class GuardServiceUnavailable extends Schema.TaggedErrorClass<GuardServiceUnavailable>(
|
|
462
|
+
`${ReasonTypeId}/GuardServiceUnavailable`,
|
|
463
|
+
)("GuardServiceUnavailable", {
|
|
464
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
465
|
+
}) {
|
|
466
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
467
|
+
override get message() {
|
|
468
|
+
return this.cause.message;
|
|
469
|
+
}
|
|
470
|
+
get group() {
|
|
471
|
+
return this.cause.group;
|
|
472
|
+
}
|
|
473
|
+
get code() {
|
|
474
|
+
return this.cause.code;
|
|
475
|
+
}
|
|
476
|
+
get metadata() {
|
|
477
|
+
return this.cause.metadata;
|
|
478
|
+
}
|
|
479
|
+
get actor() {
|
|
480
|
+
return this.cause.actor;
|
|
481
|
+
}
|
|
482
|
+
get statusCode() {
|
|
483
|
+
return this.cause.statusCode;
|
|
484
|
+
}
|
|
485
|
+
get public() {
|
|
486
|
+
return this.cause.public;
|
|
487
|
+
}
|
|
488
|
+
get isRetryable(): boolean {
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export class GuardActorStoppedWhileWaiting extends Schema.TaggedErrorClass<GuardActorStoppedWhileWaiting>(
|
|
494
|
+
`${ReasonTypeId}/GuardActorStoppedWhileWaiting`,
|
|
495
|
+
)("GuardActorStoppedWhileWaiting", {
|
|
496
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
497
|
+
}) {
|
|
498
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
499
|
+
override get message() {
|
|
500
|
+
return this.cause.message;
|
|
501
|
+
}
|
|
502
|
+
get group() {
|
|
503
|
+
return this.cause.group;
|
|
504
|
+
}
|
|
505
|
+
get code() {
|
|
506
|
+
return this.cause.code;
|
|
507
|
+
}
|
|
508
|
+
get metadata() {
|
|
509
|
+
return this.cause.metadata;
|
|
510
|
+
}
|
|
511
|
+
get actor() {
|
|
512
|
+
return this.cause.actor;
|
|
513
|
+
}
|
|
514
|
+
get statusCode() {
|
|
515
|
+
return this.cause.statusCode;
|
|
516
|
+
}
|
|
517
|
+
get public() {
|
|
518
|
+
return this.cause.public;
|
|
519
|
+
}
|
|
520
|
+
get isRetryable(): boolean {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export class GuardTunnelRequestAborted extends Schema.TaggedErrorClass<GuardTunnelRequestAborted>(
|
|
526
|
+
`${ReasonTypeId}/GuardTunnelRequestAborted`,
|
|
527
|
+
)("GuardTunnelRequestAborted", {
|
|
528
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
529
|
+
}) {
|
|
530
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
531
|
+
override get message() {
|
|
532
|
+
return this.cause.message;
|
|
533
|
+
}
|
|
534
|
+
get group() {
|
|
535
|
+
return this.cause.group;
|
|
536
|
+
}
|
|
537
|
+
get code() {
|
|
538
|
+
return this.cause.code;
|
|
539
|
+
}
|
|
540
|
+
get metadata() {
|
|
541
|
+
return this.cause.metadata;
|
|
542
|
+
}
|
|
543
|
+
get actor() {
|
|
544
|
+
return this.cause.actor;
|
|
545
|
+
}
|
|
546
|
+
get statusCode() {
|
|
547
|
+
return this.cause.statusCode;
|
|
548
|
+
}
|
|
549
|
+
get public() {
|
|
550
|
+
return this.cause.public;
|
|
551
|
+
}
|
|
552
|
+
get isRetryable(): boolean {
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export class GuardTunnelMessageTimeout extends Schema.TaggedErrorClass<GuardTunnelMessageTimeout>(
|
|
558
|
+
`${ReasonTypeId}/GuardTunnelMessageTimeout`,
|
|
559
|
+
)("GuardTunnelMessageTimeout", {
|
|
560
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
561
|
+
}) {
|
|
562
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
563
|
+
override get message() {
|
|
564
|
+
return this.cause.message;
|
|
565
|
+
}
|
|
566
|
+
get group() {
|
|
567
|
+
return this.cause.group;
|
|
568
|
+
}
|
|
569
|
+
get code() {
|
|
570
|
+
return this.cause.code;
|
|
571
|
+
}
|
|
572
|
+
get metadata() {
|
|
573
|
+
return this.cause.metadata;
|
|
574
|
+
}
|
|
575
|
+
get actor() {
|
|
576
|
+
return this.cause.actor;
|
|
577
|
+
}
|
|
578
|
+
get statusCode() {
|
|
579
|
+
return this.cause.statusCode;
|
|
580
|
+
}
|
|
581
|
+
get public() {
|
|
582
|
+
return this.cause.public;
|
|
583
|
+
}
|
|
584
|
+
get isRetryable(): boolean {
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
export class GuardTunnelResponseClosed extends Schema.TaggedErrorClass<GuardTunnelResponseClosed>(
|
|
590
|
+
`${ReasonTypeId}/GuardTunnelResponseClosed`,
|
|
591
|
+
)("GuardTunnelResponseClosed", {
|
|
592
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
593
|
+
}) {
|
|
594
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
595
|
+
override get message() {
|
|
596
|
+
return this.cause.message;
|
|
597
|
+
}
|
|
598
|
+
get group() {
|
|
599
|
+
return this.cause.group;
|
|
600
|
+
}
|
|
601
|
+
get code() {
|
|
602
|
+
return this.cause.code;
|
|
603
|
+
}
|
|
604
|
+
get metadata() {
|
|
605
|
+
return this.cause.metadata;
|
|
606
|
+
}
|
|
607
|
+
get actor() {
|
|
608
|
+
return this.cause.actor;
|
|
609
|
+
}
|
|
610
|
+
get statusCode() {
|
|
611
|
+
return this.cause.statusCode;
|
|
612
|
+
}
|
|
613
|
+
get public() {
|
|
614
|
+
return this.cause.public;
|
|
615
|
+
}
|
|
616
|
+
get isRetryable(): boolean {
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
export class GuardGatewayResponseStartTimeout extends Schema.TaggedErrorClass<GuardGatewayResponseStartTimeout>(
|
|
622
|
+
`${ReasonTypeId}/GuardGatewayResponseStartTimeout`,
|
|
623
|
+
)("GuardGatewayResponseStartTimeout", {
|
|
624
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
625
|
+
}) {
|
|
626
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
627
|
+
override get message() {
|
|
628
|
+
return this.cause.message;
|
|
629
|
+
}
|
|
630
|
+
get group() {
|
|
631
|
+
return this.cause.group;
|
|
632
|
+
}
|
|
633
|
+
get code() {
|
|
634
|
+
return this.cause.code;
|
|
635
|
+
}
|
|
636
|
+
get metadata() {
|
|
637
|
+
return this.cause.metadata;
|
|
638
|
+
}
|
|
639
|
+
get actor() {
|
|
640
|
+
return this.cause.actor;
|
|
641
|
+
}
|
|
642
|
+
get statusCode() {
|
|
643
|
+
return this.cause.statusCode;
|
|
644
|
+
}
|
|
645
|
+
get public() {
|
|
646
|
+
return this.cause.public;
|
|
647
|
+
}
|
|
648
|
+
get isRetryable(): boolean {
|
|
649
|
+
return true;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export class InternalError extends Schema.TaggedErrorClass<InternalError>(
|
|
654
|
+
`${ReasonTypeId}/InternalError`,
|
|
655
|
+
)("InternalError", {
|
|
656
|
+
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
657
|
+
}) {
|
|
658
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
659
|
+
override get message() {
|
|
660
|
+
return this.cause.message;
|
|
661
|
+
}
|
|
662
|
+
get group() {
|
|
663
|
+
return this.cause.group;
|
|
664
|
+
}
|
|
665
|
+
get code() {
|
|
666
|
+
return this.cause.code;
|
|
667
|
+
}
|
|
668
|
+
get metadata() {
|
|
669
|
+
return this.cause.metadata;
|
|
670
|
+
}
|
|
671
|
+
get actor() {
|
|
672
|
+
return this.cause.actor;
|
|
673
|
+
}
|
|
674
|
+
get statusCode() {
|
|
675
|
+
return this.cause.statusCode;
|
|
676
|
+
}
|
|
677
|
+
get public() {
|
|
678
|
+
return this.cause.public;
|
|
679
|
+
}
|
|
680
|
+
get isRetryable(): boolean {
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
export class ActionErrorDecodeFailed extends Schema.TaggedErrorClass<ActionErrorDecodeFailed>(
|
|
686
|
+
`${ReasonTypeId}/ActionErrorDecodeFailed`,
|
|
687
|
+
)("ActionErrorDecodeFailed", {
|
|
688
|
+
cause: Schema.instanceOf(Schema.SchemaError),
|
|
689
|
+
rivetError: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
690
|
+
}) {
|
|
691
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
692
|
+
override get message() {
|
|
693
|
+
return `Failed to decode action error ${this.rivetError.group}.${this.rivetError.code}`;
|
|
694
|
+
}
|
|
695
|
+
get group() {
|
|
696
|
+
return this.rivetError.group;
|
|
697
|
+
}
|
|
698
|
+
get code() {
|
|
699
|
+
return this.rivetError.code;
|
|
700
|
+
}
|
|
701
|
+
get metadata() {
|
|
702
|
+
return this.rivetError.metadata;
|
|
703
|
+
}
|
|
704
|
+
get actor() {
|
|
705
|
+
return this.rivetError.actor;
|
|
706
|
+
}
|
|
707
|
+
get statusCode() {
|
|
708
|
+
return this.rivetError.statusCode;
|
|
709
|
+
}
|
|
710
|
+
get public() {
|
|
711
|
+
return this.rivetError.public;
|
|
712
|
+
}
|
|
713
|
+
get isRetryable(): boolean {
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Open-ended user error reason. Used when the actor threw `UserError` but
|
|
720
|
+
* the failing action did not declare a matching schema in its `error`
|
|
721
|
+
* field — so we can't surface it as a typed domain error in the Effect
|
|
722
|
+
* error channel.
|
|
723
|
+
*
|
|
724
|
+
* Actions that declare their user errors via `Action.make({ error: ... })`
|
|
725
|
+
* receive those errors **typed** in the error channel; this reason is
|
|
726
|
+
* the catch-all for everything else.
|
|
727
|
+
*/
|
|
728
|
+
export class UnknownUserError extends Schema.TaggedErrorClass<UnknownUserError>(
|
|
729
|
+
`${ReasonTypeId}/UnknownUserError`,
|
|
730
|
+
)("UnknownUserError", { cause: Schema.instanceOf(RivetkitErrors.RivetError) }) {
|
|
731
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
732
|
+
override get message() {
|
|
733
|
+
return this.cause.message;
|
|
734
|
+
}
|
|
735
|
+
get group() {
|
|
736
|
+
return this.cause.group;
|
|
737
|
+
}
|
|
738
|
+
get code() {
|
|
739
|
+
return this.cause.code;
|
|
740
|
+
}
|
|
741
|
+
get metadata() {
|
|
742
|
+
return this.cause.metadata;
|
|
743
|
+
}
|
|
744
|
+
get actor() {
|
|
745
|
+
return this.cause.actor;
|
|
746
|
+
}
|
|
747
|
+
get statusCode() {
|
|
748
|
+
return this.cause.statusCode;
|
|
749
|
+
}
|
|
750
|
+
get public() {
|
|
751
|
+
return this.cause.public;
|
|
752
|
+
}
|
|
753
|
+
get isRetryable(): boolean {
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Forward-compatible catch-all for `(group, code)` pairs the SDK does
|
|
760
|
+
* not recognize yet, and for malformed non-Rivet failures. Known wire
|
|
761
|
+
* fields are mirrored when present, while `cause` preserves the raw input.
|
|
762
|
+
*/
|
|
763
|
+
export class UnknownError extends Schema.TaggedErrorClass<UnknownError>(
|
|
764
|
+
`${ReasonTypeId}/UnknownError`,
|
|
765
|
+
)("UnknownError", {
|
|
766
|
+
message: Schema.String,
|
|
767
|
+
cause: Schema.Unknown,
|
|
768
|
+
}) {
|
|
769
|
+
readonly [ReasonTypeId] = ReasonTypeId;
|
|
770
|
+
get group() {
|
|
771
|
+
return this.cause instanceof RivetkitErrors.RivetError
|
|
772
|
+
? this.cause.group
|
|
773
|
+
: undefined;
|
|
774
|
+
}
|
|
775
|
+
get code() {
|
|
776
|
+
return this.cause instanceof RivetkitErrors.RivetError
|
|
777
|
+
? this.cause.code
|
|
778
|
+
: undefined;
|
|
779
|
+
}
|
|
780
|
+
get metadata() {
|
|
781
|
+
return this.cause instanceof RivetkitErrors.RivetError
|
|
782
|
+
? this.cause.metadata
|
|
783
|
+
: undefined;
|
|
784
|
+
}
|
|
785
|
+
get actor() {
|
|
786
|
+
return this.cause instanceof RivetkitErrors.RivetError
|
|
787
|
+
? this.cause.actor
|
|
788
|
+
: undefined;
|
|
789
|
+
}
|
|
790
|
+
get statusCode() {
|
|
791
|
+
return this.cause instanceof RivetkitErrors.RivetError
|
|
792
|
+
? this.cause.statusCode
|
|
793
|
+
: undefined;
|
|
794
|
+
}
|
|
795
|
+
get public() {
|
|
796
|
+
return this.cause instanceof RivetkitErrors.RivetError
|
|
797
|
+
? this.cause.public
|
|
798
|
+
: undefined;
|
|
799
|
+
}
|
|
800
|
+
get isRetryable(): boolean {
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
export type RivetErrorReason =
|
|
806
|
+
| Forbidden
|
|
807
|
+
| ActorNotFound
|
|
808
|
+
| ActorStopping
|
|
809
|
+
| ActorRestarting
|
|
810
|
+
| ActionNotFound
|
|
811
|
+
| ActionTimedOut
|
|
812
|
+
| ActionAborted
|
|
813
|
+
| ActorOverloaded
|
|
814
|
+
| IncomingMessageTooLong
|
|
815
|
+
| OutgoingMessageTooLong
|
|
816
|
+
| InvalidEncoding
|
|
817
|
+
| InvalidRequest
|
|
818
|
+
| GuardActorReadyTimeout
|
|
819
|
+
| GuardActorRunnerFailed
|
|
820
|
+
| GuardServiceUnavailable
|
|
821
|
+
| GuardActorStoppedWhileWaiting
|
|
822
|
+
| GuardTunnelRequestAborted
|
|
823
|
+
| GuardTunnelMessageTimeout
|
|
824
|
+
| GuardTunnelResponseClosed
|
|
825
|
+
| GuardGatewayResponseStartTimeout
|
|
826
|
+
| InternalError
|
|
827
|
+
| UnknownUserError
|
|
828
|
+
| ActionErrorDecodeFailed
|
|
829
|
+
| UnknownError;
|
|
830
|
+
|
|
831
|
+
export const RivetErrorReason: Schema.Union<
|
|
832
|
+
[
|
|
833
|
+
typeof Forbidden,
|
|
834
|
+
typeof ActorNotFound,
|
|
835
|
+
typeof ActorStopping,
|
|
836
|
+
typeof ActorRestarting,
|
|
837
|
+
typeof ActionNotFound,
|
|
838
|
+
typeof ActionTimedOut,
|
|
839
|
+
typeof ActionAborted,
|
|
840
|
+
typeof ActorOverloaded,
|
|
841
|
+
typeof IncomingMessageTooLong,
|
|
842
|
+
typeof OutgoingMessageTooLong,
|
|
843
|
+
typeof InvalidEncoding,
|
|
844
|
+
typeof InvalidRequest,
|
|
845
|
+
typeof GuardActorReadyTimeout,
|
|
846
|
+
typeof GuardActorRunnerFailed,
|
|
847
|
+
typeof GuardServiceUnavailable,
|
|
848
|
+
typeof GuardActorStoppedWhileWaiting,
|
|
849
|
+
typeof GuardTunnelRequestAborted,
|
|
850
|
+
typeof GuardTunnelMessageTimeout,
|
|
851
|
+
typeof GuardTunnelResponseClosed,
|
|
852
|
+
typeof GuardGatewayResponseStartTimeout,
|
|
853
|
+
typeof InternalError,
|
|
854
|
+
typeof ActionErrorDecodeFailed,
|
|
855
|
+
typeof UnknownUserError,
|
|
856
|
+
typeof UnknownError,
|
|
857
|
+
]
|
|
858
|
+
> = Schema.Union([
|
|
859
|
+
Forbidden,
|
|
860
|
+
ActorNotFound,
|
|
861
|
+
ActorStopping,
|
|
862
|
+
ActorRestarting,
|
|
863
|
+
ActionNotFound,
|
|
864
|
+
ActionTimedOut,
|
|
865
|
+
ActionAborted,
|
|
866
|
+
ActorOverloaded,
|
|
867
|
+
IncomingMessageTooLong,
|
|
868
|
+
OutgoingMessageTooLong,
|
|
869
|
+
InvalidEncoding,
|
|
870
|
+
InvalidRequest,
|
|
871
|
+
GuardActorReadyTimeout,
|
|
872
|
+
GuardActorRunnerFailed,
|
|
873
|
+
GuardServiceUnavailable,
|
|
874
|
+
GuardActorStoppedWhileWaiting,
|
|
875
|
+
GuardTunnelRequestAborted,
|
|
876
|
+
GuardTunnelMessageTimeout,
|
|
877
|
+
GuardTunnelResponseClosed,
|
|
878
|
+
GuardGatewayResponseStartTimeout,
|
|
879
|
+
InternalError,
|
|
880
|
+
ActionErrorDecodeFailed,
|
|
881
|
+
UnknownUserError,
|
|
882
|
+
UnknownError,
|
|
883
|
+
]);
|
|
884
|
+
|
|
885
|
+
export const isRivetErrorReason = (u: unknown): u is RivetErrorReason =>
|
|
886
|
+
Predicate.hasProperty(u, ReasonTypeId);
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* The infrastructure-failure error surfaced by `@rivetkit/effect`
|
|
890
|
+
* calls. Wraps a discriminated `reason` of all known failure
|
|
891
|
+
* modes.
|
|
892
|
+
*
|
|
893
|
+
* Recover with `Effect.catchReason` / `Effect.catchReasons` /
|
|
894
|
+
* `Effect.unwrapReason`:
|
|
895
|
+
*
|
|
896
|
+
* ```ts
|
|
897
|
+
* program.pipe(
|
|
898
|
+
* Effect.catchReasons("RivetError", {
|
|
899
|
+
* Forbidden: () => Effect.fail(new MyAuthError()),
|
|
900
|
+
* ConnectionLost: () => Effect.logWarning("reconnecting"),
|
|
901
|
+
* }),
|
|
902
|
+
* )
|
|
903
|
+
* ```
|
|
904
|
+
*
|
|
905
|
+
* User-defined errors declared on an action via `Action.make({ error })`
|
|
906
|
+
* arrive in the typed error channel separately and do NOT flow through
|
|
907
|
+
* `RivetError`.
|
|
908
|
+
*/
|
|
909
|
+
export class RivetError extends Schema.TaggedErrorClass<RivetError>(
|
|
910
|
+
"@rivetkit/effect/RivetError",
|
|
911
|
+
)("RivetError", {
|
|
912
|
+
reason: RivetErrorReason,
|
|
913
|
+
}) {
|
|
914
|
+
/** Marks this value as the top-level Rivet error wrapper for runtime guards. */
|
|
915
|
+
readonly [TypeId] = TypeId;
|
|
916
|
+
|
|
917
|
+
/** Exposes the structured Rivet error reason as the JavaScript error cause. */
|
|
918
|
+
override readonly cause = this.reason;
|
|
919
|
+
|
|
920
|
+
/** Uses the reason message when present, otherwise falls back to the reason tag. */
|
|
921
|
+
override get message() {
|
|
922
|
+
return this.reason.message || this.reason._tag;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/** Delegates to the underlying reason's `group` if present. */
|
|
926
|
+
get group(): string | undefined {
|
|
927
|
+
return "group" in this.reason ? this.reason.group : undefined;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** Delegates to the underlying reason's `code` if present. */
|
|
931
|
+
get code(): string | undefined {
|
|
932
|
+
return "code" in this.reason ? this.reason.code : undefined;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/** Delegates to the underlying reason's `metadata` if present. */
|
|
936
|
+
get metadata(): unknown {
|
|
937
|
+
return "metadata" in this.reason ? this.reason.metadata : undefined;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/** Delegates to the underlying reason's `actor` if present. */
|
|
941
|
+
get actor() {
|
|
942
|
+
return "actor" in this.reason ? this.reason.actor : undefined;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/** Delegates to the underlying reason's `statusCode` if present. */
|
|
946
|
+
get statusCode(): number | undefined {
|
|
947
|
+
return "statusCode" in this.reason ? this.reason.statusCode : undefined;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/** Delegates to the underlying reason's `public` if present. */
|
|
951
|
+
get public(): boolean | undefined {
|
|
952
|
+
return "public" in this.reason ? this.reason.public : undefined;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** Delegates to the underlying reason's `isRetryable` getter. */
|
|
956
|
+
get isRetryable(): boolean {
|
|
957
|
+
return this.reason.isRetryable;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/** Delegates to the underlying reason's `retryAfter` if present. */
|
|
961
|
+
get retryAfter(): Duration.Duration | undefined {
|
|
962
|
+
return "retryAfter" in this.reason ? this.reason.retryAfter : undefined;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
export const isRivetError = (u: unknown): u is RivetError =>
|
|
967
|
+
Predicate.hasProperty(u, TypeId);
|
|
968
|
+
|
|
969
|
+
type MakeRivetErrorReason = (
|
|
970
|
+
error: RivetkitErrors.RivetError,
|
|
971
|
+
) => RivetErrorReason;
|
|
972
|
+
|
|
973
|
+
const reasonByCode: { [key: string]: MakeRivetErrorReason | undefined } = {
|
|
974
|
+
"auth.forbidden": (error) => new Forbidden({ cause: error }),
|
|
975
|
+
"actor.not_found": (error) => new ActorNotFound({ cause: error }),
|
|
976
|
+
"actor.stopping": (error) => new ActorStopping({ cause: error }),
|
|
977
|
+
"actor.restarting": (error) => new ActorRestarting({ cause: error }),
|
|
978
|
+
"actor.action_not_found": (error) => new ActionNotFound({ cause: error }),
|
|
979
|
+
"actor.action_timed_out": (error) => new ActionTimedOut({ cause: error }),
|
|
980
|
+
"actor.aborted": (error) => new ActionAborted({ cause: error }),
|
|
981
|
+
"actor.overloaded": (error) => new ActorOverloaded({ cause: error }),
|
|
982
|
+
[`actor.${RivetkitErrors.INTERNAL_ERROR_CODE}`]: (error) =>
|
|
983
|
+
new InternalError({ cause: error }),
|
|
984
|
+
[`core.${RivetkitErrors.INTERNAL_ERROR_CODE}`]: (error) =>
|
|
985
|
+
new InternalError({ cause: error }),
|
|
986
|
+
[`rivetkit.${RivetkitErrors.INTERNAL_ERROR_CODE}`]: (error) =>
|
|
987
|
+
new InternalError({ cause: error }),
|
|
988
|
+
"message.incoming_too_long": (error) =>
|
|
989
|
+
new IncomingMessageTooLong({ cause: error }),
|
|
990
|
+
"message.outgoing_too_long": (error) =>
|
|
991
|
+
new OutgoingMessageTooLong({ cause: error }),
|
|
992
|
+
"encoding.invalid": (error) => new InvalidEncoding({ cause: error }),
|
|
993
|
+
"request.invalid": (error) => new InvalidRequest({ cause: error }),
|
|
994
|
+
"guard.actor_ready_timeout": (error) =>
|
|
995
|
+
new GuardActorReadyTimeout({ cause: error }),
|
|
996
|
+
"guard.actor_runner_failed": (error) =>
|
|
997
|
+
new GuardActorRunnerFailed({ cause: error }),
|
|
998
|
+
"guard.service_unavailable": (error) =>
|
|
999
|
+
new GuardServiceUnavailable({ cause: error }),
|
|
1000
|
+
"guard.actor_stopped_while_waiting": (error) =>
|
|
1001
|
+
new GuardActorStoppedWhileWaiting({ cause: error }),
|
|
1002
|
+
"guard.tunnel_request_aborted": (error) =>
|
|
1003
|
+
new GuardTunnelRequestAborted({ cause: error }),
|
|
1004
|
+
"guard.tunnel_message_timeout": (error) =>
|
|
1005
|
+
new GuardTunnelMessageTimeout({ cause: error }),
|
|
1006
|
+
"guard.tunnel_response_closed": (error) =>
|
|
1007
|
+
new GuardTunnelResponseClosed({ cause: error }),
|
|
1008
|
+
"guard.gateway_response_start_timeout": (error) =>
|
|
1009
|
+
new GuardGatewayResponseStartTimeout({ cause: error }),
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
const reasonFromRivetkitRivetError = (
|
|
1013
|
+
error: RivetkitErrors.RivetError,
|
|
1014
|
+
): RivetErrorReason => {
|
|
1015
|
+
const makeReason = reasonByCode[`${error.group}.${error.code}`];
|
|
1016
|
+
if (makeReason) return makeReason(error);
|
|
1017
|
+
|
|
1018
|
+
if (error.group === "user") return new UnknownUserError({ cause: error });
|
|
1019
|
+
|
|
1020
|
+
return new UnknownError({
|
|
1021
|
+
message: error.message,
|
|
1022
|
+
cause: error,
|
|
1023
|
+
});
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
export const fromRivetkitRivetError = (
|
|
1027
|
+
error: RivetkitErrors.RivetError,
|
|
1028
|
+
): RivetError => {
|
|
1029
|
+
return new RivetError({ reason: reasonFromRivetkitRivetError(error) });
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
export const fromUnknown = (cause: unknown): RivetError => {
|
|
1033
|
+
if (isRivetError(cause)) return cause;
|
|
1034
|
+
if (RivetkitErrors.isRivetErrorLike(cause)) {
|
|
1035
|
+
return fromRivetkitRivetError(RivetkitErrors.toRivetError(cause));
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
return new RivetError({
|
|
1039
|
+
reason: new UnknownError({
|
|
1040
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
1041
|
+
cause,
|
|
1042
|
+
}),
|
|
1043
|
+
});
|
|
1044
|
+
};
|