@rivetkit/effect 0.0.0-sqlite-sync-3-0-6-final.cf8679c → 0.0.0-sqlite-query-metrics-2-3-32.5bb1917
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/Actor.d.ts +1 -26
- package/dist/Actor.d.ts.map +1 -1
- package/dist/Actor.js +0 -1
- package/dist/Actor.js.map +1 -1
- package/dist/RivetError.d.ts +3 -19
- package/dist/RivetError.d.ts.map +1 -1
- package/dist/RivetError.js +0 -34
- package/dist/RivetError.js.map +1 -1
- package/dist/internal/ActionDispatcher.d.ts +3 -3
- package/dist/internal/ActionDispatcher.d.ts.map +1 -1
- package/dist/internal/ActionDispatcher.js +1 -23
- package/dist/internal/ActionDispatcher.js.map +1 -1
- package/dist/internal/ActorInstanceManager.d.ts +0 -7
- package/dist/internal/ActorInstanceManager.d.ts.map +1 -1
- package/dist/internal/ActorInstanceManager.js +0 -40
- package/dist/internal/ActorInstanceManager.js.map +1 -1
- package/dist/mod.d.ts +0 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +0 -1
- package/dist/mod.js.map +1 -1
- package/package.json +4 -5
- package/src/Actor.test-d.ts +641 -0
- package/src/Actor.test.ts +209 -0
- package/src/Actor.ts +0 -28
- package/src/Client.test.ts +206 -0
- package/src/Registry.test-d.ts +126 -0
- package/src/Registry.test.ts +400 -0
- package/src/RivetError.test.ts +199 -0
- package/src/RivetError.ts +0 -40
- package/src/State.test.ts +340 -0
- package/src/internal/ActionDispatcher.ts +4 -35
- package/src/internal/ActorInstanceManager.ts +0 -54
- package/src/internal/logging.test.ts +274 -0
- package/src/mod.ts +0 -1
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
+
import { Action, Actor, Registry, RivetLogger } from "@rivetkit/effect";
|
|
3
|
+
import { Effect, Layer } from "effect";
|
|
4
|
+
import { HttpEffect } from "effect/http";
|
|
5
|
+
import * as RivetkitLog from "rivetkit/log";
|
|
6
|
+
import { vi } from "vitest";
|
|
7
|
+
|
|
8
|
+
const TestActor = Actor.make("TestActor", {
|
|
9
|
+
actions: [Action.make("Test")],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const TestActorLive = TestActor.toLayer({
|
|
13
|
+
Test: () => Effect.void,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const ActorsLayer = Layer.mergeAll(TestActorLive);
|
|
17
|
+
|
|
18
|
+
const RegistryLive = ActorsLayer.pipe(
|
|
19
|
+
Layer.provideMerge(
|
|
20
|
+
Registry.layer({
|
|
21
|
+
endpoint: "http://127.0.0.1:6420",
|
|
22
|
+
noWelcome: true,
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
function makeTestLogger(): RivetkitLog.Logger {
|
|
28
|
+
const logger: Record<string, unknown> = {
|
|
29
|
+
level: "debug",
|
|
30
|
+
child: () => logger,
|
|
31
|
+
};
|
|
32
|
+
for (const level of ["trace", "debug", "info", "warn", "error", "fatal"]) {
|
|
33
|
+
logger[level] = (): void => {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return logger as unknown as RivetkitLog.Logger;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe("Registry.toWebHandler", () => {
|
|
40
|
+
it("serves registered actors as a Fetch handler", async () => {
|
|
41
|
+
const { handler, dispose } = Registry.toWebHandler(RegistryLive);
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const response = await handler(
|
|
45
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
assert.strictEqual(response.status, 200);
|
|
49
|
+
const body = (await response.json()) as {
|
|
50
|
+
readonly actorNames: Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
assert.ok(body.actorNames.TestActor);
|
|
53
|
+
} finally {
|
|
54
|
+
await dispose();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("uses a custom serverless base path", async () => {
|
|
59
|
+
const { handler, dispose } = Registry.toWebHandler(RegistryLive, {
|
|
60
|
+
basePath: "/",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const response = await handler(
|
|
65
|
+
new Request("http://runner.test/metadata"),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
assert.strictEqual(response.status, 200);
|
|
69
|
+
const body = (await response.json()) as {
|
|
70
|
+
readonly actorNames: Record<string, unknown>;
|
|
71
|
+
};
|
|
72
|
+
assert.ok(body.actorNames.TestActor);
|
|
73
|
+
} finally {
|
|
74
|
+
await dispose();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("uses the custom base path to identify start requests", async () => {
|
|
79
|
+
const { handler, dispose } = Registry.toWebHandler(RegistryLive, {
|
|
80
|
+
basePath: "/custom",
|
|
81
|
+
maxStartPayloadBytes: 1,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const defaultPrefix = await handler(
|
|
86
|
+
new Request("http://runner.test/api/rivet/start", {
|
|
87
|
+
method: "POST",
|
|
88
|
+
body: new Uint8Array([1, 2]),
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
assert.notStrictEqual(defaultPrefix.status, 413);
|
|
92
|
+
|
|
93
|
+
const customPrefix = await handler(
|
|
94
|
+
new Request("http://runner.test/custom/start", {
|
|
95
|
+
method: "POST",
|
|
96
|
+
body: new Uint8Array([1, 2]),
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
assert.strictEqual(customPrefix.status, 413);
|
|
100
|
+
const body = (await customPrefix.json()) as {
|
|
101
|
+
readonly group: string;
|
|
102
|
+
readonly code: string;
|
|
103
|
+
readonly message: string;
|
|
104
|
+
};
|
|
105
|
+
assert.deepStrictEqual(
|
|
106
|
+
{ group: body.group, code: body.code },
|
|
107
|
+
{ group: "message", code: "incoming_too_long" },
|
|
108
|
+
);
|
|
109
|
+
assert.match(body.message, /limit is 1 bytes/);
|
|
110
|
+
} finally {
|
|
111
|
+
await dispose();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("uses a custom serverless start payload size limit", async () => {
|
|
116
|
+
const { handler, dispose } = Registry.toWebHandler(RegistryLive, {
|
|
117
|
+
maxStartPayloadBytes: 1,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const response = await handler(
|
|
122
|
+
new Request("http://runner.test/api/rivet/start", {
|
|
123
|
+
method: "POST",
|
|
124
|
+
body: new Uint8Array([1, 2]),
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
assert.strictEqual(response.status, 413);
|
|
129
|
+
const body = (await response.json()) as {
|
|
130
|
+
readonly group: string;
|
|
131
|
+
readonly code: string;
|
|
132
|
+
readonly message: string;
|
|
133
|
+
};
|
|
134
|
+
assert.deepStrictEqual(
|
|
135
|
+
{ group: body.group, code: body.code },
|
|
136
|
+
{ group: "message", code: "incoming_too_long" },
|
|
137
|
+
);
|
|
138
|
+
assert.match(body.message, /limit is 1 bytes/);
|
|
139
|
+
} finally {
|
|
140
|
+
await dispose();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("does not print the welcome banner when disabled", async () => {
|
|
145
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
146
|
+
const { handler, dispose } = Registry.toWebHandler(RegistryLive);
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const response = await handler(
|
|
150
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
assert.strictEqual(response.status, 200);
|
|
154
|
+
assert.strictEqual(log.mock.calls.length, 0);
|
|
155
|
+
} finally {
|
|
156
|
+
await dispose();
|
|
157
|
+
log.mockRestore();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("builds the registry layer once across requests", async () => {
|
|
162
|
+
let builds = 0;
|
|
163
|
+
const CountingRegistryLive = Layer.mergeAll(
|
|
164
|
+
RegistryLive,
|
|
165
|
+
Layer.effectDiscard(
|
|
166
|
+
Effect.sync(() => {
|
|
167
|
+
builds += 1;
|
|
168
|
+
}),
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
const { handler, dispose } =
|
|
172
|
+
Registry.toWebHandler(CountingRegistryLive);
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
const first = await handler(
|
|
176
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
177
|
+
);
|
|
178
|
+
const second = await handler(
|
|
179
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
assert.strictEqual(first.status, 200);
|
|
183
|
+
assert.strictEqual(second.status, 200);
|
|
184
|
+
assert.strictEqual(builds, 1);
|
|
185
|
+
} finally {
|
|
186
|
+
await dispose();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("initializes the underlying RivetKit registry once across requests", async () => {
|
|
191
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
192
|
+
const WelcomeRegistryLive = ActorsLayer.pipe(
|
|
193
|
+
Layer.provideMerge(
|
|
194
|
+
Registry.layer({
|
|
195
|
+
endpoint: "http://127.0.0.1:6420",
|
|
196
|
+
}),
|
|
197
|
+
),
|
|
198
|
+
);
|
|
199
|
+
const { handler, dispose } = Registry.toWebHandler(WelcomeRegistryLive);
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
const first = await handler(
|
|
203
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
204
|
+
);
|
|
205
|
+
const callsAfterFirst = log.mock.calls.length;
|
|
206
|
+
const second = await handler(
|
|
207
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
assert.strictEqual(first.status, 200);
|
|
211
|
+
assert.strictEqual(second.status, 200);
|
|
212
|
+
assert.ok(callsAfterFirst > 0);
|
|
213
|
+
assert.strictEqual(log.mock.calls.length, callsAfterFirst);
|
|
214
|
+
} finally {
|
|
215
|
+
await dispose();
|
|
216
|
+
log.mockRestore();
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("uses a custom logger layer for the underlying RivetKit registry", async () => {
|
|
221
|
+
const baseLogger = makeTestLogger();
|
|
222
|
+
const CustomLoggerRegistryLive = RegistryLive.pipe(
|
|
223
|
+
Layer.provide(RivetLogger.layerFromPino(baseLogger)),
|
|
224
|
+
);
|
|
225
|
+
const { handler, dispose } = Registry.toWebHandler(
|
|
226
|
+
CustomLoggerRegistryLive,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
const response = await handler(
|
|
231
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
assert.strictEqual(response.status, 200);
|
|
235
|
+
assert.strictEqual(RivetkitLog.getBaseLogger(), baseLogger);
|
|
236
|
+
} finally {
|
|
237
|
+
await dispose();
|
|
238
|
+
RivetkitLog.configureDefaultLogger("silent");
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("closes registry layer finalizers on dispose", async () => {
|
|
243
|
+
let finalizers = 0;
|
|
244
|
+
const FinalizedRegistryLive = Layer.mergeAll(
|
|
245
|
+
RegistryLive,
|
|
246
|
+
Layer.effectDiscard(
|
|
247
|
+
Effect.addFinalizer(() =>
|
|
248
|
+
Effect.sync(() => {
|
|
249
|
+
finalizers += 1;
|
|
250
|
+
}),
|
|
251
|
+
),
|
|
252
|
+
),
|
|
253
|
+
);
|
|
254
|
+
const { handler, dispose } = Registry.toWebHandler(
|
|
255
|
+
FinalizedRegistryLive,
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
const response = await handler(
|
|
260
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
assert.strictEqual(response.status, 200);
|
|
264
|
+
assert.strictEqual(finalizers, 0);
|
|
265
|
+
} finally {
|
|
266
|
+
await dispose();
|
|
267
|
+
}
|
|
268
|
+
assert.strictEqual(finalizers, 1);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe("Registry.toHttpEffect", () => {
|
|
273
|
+
it.effect("serves registered actors as an Effect HTTP handler", () =>
|
|
274
|
+
Effect.scoped(
|
|
275
|
+
Effect.gen(function* () {
|
|
276
|
+
const httpEffect = yield* Registry.toHttpEffect(RegistryLive);
|
|
277
|
+
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
278
|
+
const response = yield* Effect.promise(() =>
|
|
279
|
+
handler(
|
|
280
|
+
new Request("http://runner.test/api/rivet/metadata"),
|
|
281
|
+
),
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
yield* Effect.promise(() =>
|
|
285
|
+
(async (response: Response) => {
|
|
286
|
+
assert.strictEqual(response.status, 200);
|
|
287
|
+
const body = (await response.json()) as {
|
|
288
|
+
readonly actorNames: Record<string, unknown>;
|
|
289
|
+
};
|
|
290
|
+
assert.ok(body.actorNames.TestActor);
|
|
291
|
+
})(response),
|
|
292
|
+
);
|
|
293
|
+
}),
|
|
294
|
+
),
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
it.effect("uses a custom serverless base path", () =>
|
|
298
|
+
Effect.scoped(
|
|
299
|
+
Effect.gen(function* () {
|
|
300
|
+
const httpEffect = yield* Registry.toHttpEffect(RegistryLive, {
|
|
301
|
+
basePath: "/",
|
|
302
|
+
});
|
|
303
|
+
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
304
|
+
const response = yield* Effect.promise(() =>
|
|
305
|
+
handler(new Request("http://runner.test/metadata")),
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
yield* Effect.promise(() =>
|
|
309
|
+
(async (response: Response) => {
|
|
310
|
+
assert.strictEqual(response.status, 200);
|
|
311
|
+
const body = (await response.json()) as {
|
|
312
|
+
readonly actorNames: Record<string, unknown>;
|
|
313
|
+
};
|
|
314
|
+
assert.ok(body.actorNames.TestActor);
|
|
315
|
+
})(response),
|
|
316
|
+
);
|
|
317
|
+
}),
|
|
318
|
+
),
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
it.effect("uses the custom base path to identify start requests", () =>
|
|
322
|
+
Effect.scoped(
|
|
323
|
+
Effect.gen(function* () {
|
|
324
|
+
const httpEffect = yield* Registry.toHttpEffect(RegistryLive, {
|
|
325
|
+
basePath: "/custom",
|
|
326
|
+
maxStartPayloadBytes: 1,
|
|
327
|
+
});
|
|
328
|
+
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
329
|
+
const defaultPrefix = yield* Effect.promise(() =>
|
|
330
|
+
handler(
|
|
331
|
+
new Request("http://runner.test/api/rivet/start", {
|
|
332
|
+
method: "POST",
|
|
333
|
+
body: new Uint8Array([1, 2]),
|
|
334
|
+
}),
|
|
335
|
+
),
|
|
336
|
+
);
|
|
337
|
+
assert.notStrictEqual(defaultPrefix.status, 413);
|
|
338
|
+
|
|
339
|
+
const customPrefix = yield* Effect.promise(() =>
|
|
340
|
+
handler(
|
|
341
|
+
new Request("http://runner.test/custom/start", {
|
|
342
|
+
method: "POST",
|
|
343
|
+
body: new Uint8Array([1, 2]),
|
|
344
|
+
}),
|
|
345
|
+
),
|
|
346
|
+
);
|
|
347
|
+
yield* Effect.promise(() =>
|
|
348
|
+
(async (response: Response) => {
|
|
349
|
+
assert.strictEqual(response.status, 413);
|
|
350
|
+
const body = (await response.json()) as {
|
|
351
|
+
readonly group: string;
|
|
352
|
+
readonly code: string;
|
|
353
|
+
readonly message: string;
|
|
354
|
+
};
|
|
355
|
+
assert.deepStrictEqual(
|
|
356
|
+
{ group: body.group, code: body.code },
|
|
357
|
+
{ group: "message", code: "incoming_too_long" },
|
|
358
|
+
);
|
|
359
|
+
assert.match(body.message, /limit is 1 bytes/);
|
|
360
|
+
})(customPrefix),
|
|
361
|
+
);
|
|
362
|
+
}),
|
|
363
|
+
),
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
it.effect("uses a custom serverless start payload size limit", () =>
|
|
367
|
+
Effect.scoped(
|
|
368
|
+
Effect.gen(function* () {
|
|
369
|
+
const httpEffect = yield* Registry.toHttpEffect(RegistryLive, {
|
|
370
|
+
maxStartPayloadBytes: 1,
|
|
371
|
+
});
|
|
372
|
+
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
373
|
+
const response = yield* Effect.promise(() =>
|
|
374
|
+
handler(
|
|
375
|
+
new Request("http://runner.test/api/rivet/start", {
|
|
376
|
+
method: "POST",
|
|
377
|
+
body: new Uint8Array([1, 2]),
|
|
378
|
+
}),
|
|
379
|
+
),
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
yield* Effect.promise(() =>
|
|
383
|
+
(async (response: Response) => {
|
|
384
|
+
assert.strictEqual(response.status, 413);
|
|
385
|
+
const body = (await response.json()) as {
|
|
386
|
+
readonly group: string;
|
|
387
|
+
readonly code: string;
|
|
388
|
+
readonly message: string;
|
|
389
|
+
};
|
|
390
|
+
assert.deepStrictEqual(
|
|
391
|
+
{ group: body.group, code: body.code },
|
|
392
|
+
{ group: "message", code: "incoming_too_long" },
|
|
393
|
+
);
|
|
394
|
+
assert.match(body.message, /limit is 1 bytes/);
|
|
395
|
+
})(response),
|
|
396
|
+
);
|
|
397
|
+
}),
|
|
398
|
+
),
|
|
399
|
+
);
|
|
400
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
+
import { RivetError } from "@rivetkit/effect";
|
|
3
|
+
import { Duration, Effect, Schema } from "effect";
|
|
4
|
+
import * as RivetkitErrors from "rivetkit/errors";
|
|
5
|
+
|
|
6
|
+
describe("RivetError", () => {
|
|
7
|
+
it("preserves non-Rivet causes as UnknownError", () => {
|
|
8
|
+
const cause = new Error("plain failure");
|
|
9
|
+
const error = RivetError.fromUnknown(cause);
|
|
10
|
+
|
|
11
|
+
assert.instanceOf(error, RivetError.RivetError);
|
|
12
|
+
assert.instanceOf(error.reason, RivetError.UnknownError);
|
|
13
|
+
assert.strictEqual(error.reason.message, "plain failure");
|
|
14
|
+
assert.strictEqual(error.reason.cause, cause);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("allows UnknownError to wrap arbitrary causes", () => {
|
|
18
|
+
const cause = { group: "not-a-rivet-error", code: 123 };
|
|
19
|
+
const error = new RivetError.UnknownError({
|
|
20
|
+
message: "malformed failure",
|
|
21
|
+
cause,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
assert.strictEqual(error.cause, cause);
|
|
25
|
+
assert.strictEqual(error.group, undefined);
|
|
26
|
+
assert.strictEqual(error.code, undefined);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("keeps structured Rivet errors classified by group and code", () => {
|
|
30
|
+
const cause = new RivetkitErrors.RivetError(
|
|
31
|
+
"rivetkit",
|
|
32
|
+
RivetkitErrors.INTERNAL_ERROR_CODE,
|
|
33
|
+
"internal failure",
|
|
34
|
+
);
|
|
35
|
+
const error = RivetError.fromUnknown(cause);
|
|
36
|
+
|
|
37
|
+
assert.instanceOf(error.reason, RivetError.InternalError);
|
|
38
|
+
assert.strictEqual(error.reason.group, cause.group);
|
|
39
|
+
assert.strictEqual(error.reason.code, cause.code);
|
|
40
|
+
assert.strictEqual(error.reason.message, cause.message);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("exposes normalized isRetryable on every reason", () => {
|
|
44
|
+
const restarting = RivetError.fromUnknown(
|
|
45
|
+
new RivetkitErrors.RivetError("actor", "restarting", "restarting"),
|
|
46
|
+
);
|
|
47
|
+
const forbidden = RivetError.fromUnknown(
|
|
48
|
+
new RivetkitErrors.RivetError("auth", "forbidden", "forbidden"),
|
|
49
|
+
);
|
|
50
|
+
const overloaded = RivetError.fromUnknown(
|
|
51
|
+
new RivetkitErrors.RivetError("actor", "overloaded", "overloaded"),
|
|
52
|
+
);
|
|
53
|
+
const serviceUnavailable = RivetError.fromUnknown(
|
|
54
|
+
new RivetkitErrors.RivetError(
|
|
55
|
+
"guard",
|
|
56
|
+
"service_unavailable",
|
|
57
|
+
"service unavailable",
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
const incomingTooLong = RivetError.fromUnknown(
|
|
61
|
+
new RivetkitErrors.RivetError(
|
|
62
|
+
"message",
|
|
63
|
+
"incoming_too_long",
|
|
64
|
+
"too long",
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
assert.strictEqual(restarting.isRetryable, true);
|
|
69
|
+
assert.strictEqual(restarting.reason.isRetryable, true);
|
|
70
|
+
assert.strictEqual(forbidden.isRetryable, false);
|
|
71
|
+
assert.strictEqual(overloaded.isRetryable, true);
|
|
72
|
+
assert.strictEqual(serviceUnavailable.isRetryable, true);
|
|
73
|
+
assert.strictEqual(incomingTooLong.isRetryable, false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("exposes retryAfter from ActorRestarting metadata", () => {
|
|
77
|
+
const restarting = RivetError.fromUnknown(
|
|
78
|
+
new RivetkitErrors.RivetError(
|
|
79
|
+
"actor",
|
|
80
|
+
"restarting",
|
|
81
|
+
"actor restarting",
|
|
82
|
+
{ metadata: { retryAfterMs: 250 } },
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
const restartingNoHint = RivetError.fromUnknown(
|
|
86
|
+
new RivetkitErrors.RivetError(
|
|
87
|
+
"actor",
|
|
88
|
+
"restarting",
|
|
89
|
+
"actor restarting",
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
assert.instanceOf(restarting.reason, RivetError.ActorRestarting);
|
|
94
|
+
assert.deepStrictEqual(restarting.retryAfter, Duration.millis(250));
|
|
95
|
+
assert.deepStrictEqual(
|
|
96
|
+
restarting.reason.retryAfter,
|
|
97
|
+
Duration.millis(250),
|
|
98
|
+
);
|
|
99
|
+
assert.strictEqual(restartingNoHint.retryAfter, undefined);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("returns retryAfter undefined for reasons without retry-timing hints", () => {
|
|
103
|
+
const overloaded = RivetError.fromUnknown(
|
|
104
|
+
new RivetkitErrors.RivetError("actor", "overloaded", "overloaded"),
|
|
105
|
+
);
|
|
106
|
+
assert.strictEqual(overloaded.retryAfter, undefined);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("classifies known guard errors into specific reasons", () => {
|
|
110
|
+
const serviceUnavailable = RivetError.fromUnknown(
|
|
111
|
+
new RivetkitErrors.RivetError(
|
|
112
|
+
"guard",
|
|
113
|
+
"service_unavailable",
|
|
114
|
+
"service unavailable",
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
const readyTimeout = RivetError.fromUnknown(
|
|
118
|
+
new RivetkitErrors.RivetError(
|
|
119
|
+
"guard",
|
|
120
|
+
"actor_ready_timeout",
|
|
121
|
+
"actor ready timeout",
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
const wakeRetriesExceeded = RivetError.fromUnknown(
|
|
125
|
+
new RivetkitErrors.RivetError(
|
|
126
|
+
"guard",
|
|
127
|
+
"actor_wake_retries_exceeded",
|
|
128
|
+
"actor wake retries exceeded",
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
const tunnelTimeout = RivetError.fromUnknown(
|
|
132
|
+
new RivetkitErrors.RivetError(
|
|
133
|
+
"guard",
|
|
134
|
+
"tunnel_message_timeout",
|
|
135
|
+
"tunnel message timeout",
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
assert.instanceOf(
|
|
140
|
+
serviceUnavailable.reason,
|
|
141
|
+
RivetError.GuardServiceUnavailable,
|
|
142
|
+
);
|
|
143
|
+
assert.instanceOf(
|
|
144
|
+
readyTimeout.reason,
|
|
145
|
+
RivetError.GuardActorReadyTimeout,
|
|
146
|
+
);
|
|
147
|
+
assert.instanceOf(
|
|
148
|
+
wakeRetriesExceeded.reason,
|
|
149
|
+
RivetError.GuardActorWakeRetriesExceeded,
|
|
150
|
+
);
|
|
151
|
+
assert.instanceOf(
|
|
152
|
+
tunnelTimeout.reason,
|
|
153
|
+
RivetError.GuardTunnelMessageTimeout,
|
|
154
|
+
);
|
|
155
|
+
assert.strictEqual(
|
|
156
|
+
serviceUnavailable.reason.code,
|
|
157
|
+
"service_unavailable",
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("keeps unknown guard errors in UnknownError", () => {
|
|
162
|
+
const error = RivetError.fromUnknown(
|
|
163
|
+
new RivetkitErrors.RivetError(
|
|
164
|
+
"guard",
|
|
165
|
+
"new_guard_code",
|
|
166
|
+
"new guard code",
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
assert.instanceOf(error.reason, RivetError.UnknownError);
|
|
171
|
+
assert.strictEqual(error.reason.code, "new_guard_code");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("exposes action error decode failures with decode context", () => {
|
|
175
|
+
const cause = new RivetkitErrors.RivetError(
|
|
176
|
+
"user",
|
|
177
|
+
"CounterOverflow",
|
|
178
|
+
"counter overflow",
|
|
179
|
+
{ metadata: { _tag: "EffectActionError", version: 1, error: {} } },
|
|
180
|
+
);
|
|
181
|
+
const schemaError = Effect.runSync(
|
|
182
|
+
Schema.decodeUnknownEffect(Schema.String)(123).pipe(Effect.flip),
|
|
183
|
+
);
|
|
184
|
+
const error = new RivetError.RivetError({
|
|
185
|
+
reason: new RivetError.ActionErrorDecodeFailed({
|
|
186
|
+
cause: schemaError,
|
|
187
|
+
rivetError: cause,
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
assert.instanceOf(error.reason, RivetError.ActionErrorDecodeFailed);
|
|
192
|
+
assert.strictEqual(error.reason.cause, schemaError);
|
|
193
|
+
assert.strictEqual(error.reason.rivetError, cause);
|
|
194
|
+
assert.strictEqual(
|
|
195
|
+
error.reason.message,
|
|
196
|
+
"Failed to decode action error user.CounterOverflow",
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
});
|
package/src/RivetError.ts
CHANGED
|
@@ -430,41 +430,6 @@ export class InvalidRequest extends Schema.TaggedError<InvalidRequest>(
|
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
export class GuardRequestTimeout extends Schema.TaggedError<GuardRequestTimeout>(
|
|
434
|
-
`${ReasonTypeId}/GuardRequestTimeout`,
|
|
435
|
-
)("GuardRequestTimeout", {
|
|
436
|
-
cause: Schema.instanceOf(RivetkitErrors.RivetError),
|
|
437
|
-
}) {
|
|
438
|
-
readonly [ReasonTypeId] = ReasonTypeId;
|
|
439
|
-
override get message() {
|
|
440
|
-
return this.cause.message;
|
|
441
|
-
}
|
|
442
|
-
get group() {
|
|
443
|
-
return this.cause.group;
|
|
444
|
-
}
|
|
445
|
-
get code() {
|
|
446
|
-
return this.cause.code;
|
|
447
|
-
}
|
|
448
|
-
get metadata() {
|
|
449
|
-
return this.cause.metadata;
|
|
450
|
-
}
|
|
451
|
-
get actor() {
|
|
452
|
-
return this.cause.actor;
|
|
453
|
-
}
|
|
454
|
-
get statusCode() {
|
|
455
|
-
return this.cause.statusCode;
|
|
456
|
-
}
|
|
457
|
-
get public() {
|
|
458
|
-
return this.cause.public;
|
|
459
|
-
}
|
|
460
|
-
get rayId() {
|
|
461
|
-
return this.cause.rayId;
|
|
462
|
-
}
|
|
463
|
-
get isRetryable(): boolean {
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
433
|
export class GuardActorReadyTimeout extends Schema.TaggedError<GuardActorReadyTimeout>(
|
|
469
434
|
`${ReasonTypeId}/GuardActorReadyTimeout`,
|
|
470
435
|
)("GuardActorReadyTimeout", {
|
|
@@ -959,7 +924,6 @@ export type RivetErrorReason =
|
|
|
959
924
|
| OutgoingMessageTooLong
|
|
960
925
|
| InvalidEncoding
|
|
961
926
|
| InvalidRequest
|
|
962
|
-
| GuardRequestTimeout
|
|
963
927
|
| GuardActorReadyTimeout
|
|
964
928
|
| GuardActorWakeRetriesExceeded
|
|
965
929
|
| GuardActorRunnerFailed
|
|
@@ -988,7 +952,6 @@ export const RivetErrorReason: Schema.Union<
|
|
|
988
952
|
typeof OutgoingMessageTooLong,
|
|
989
953
|
typeof InvalidEncoding,
|
|
990
954
|
typeof InvalidRequest,
|
|
991
|
-
typeof GuardRequestTimeout,
|
|
992
955
|
typeof GuardActorReadyTimeout,
|
|
993
956
|
typeof GuardActorWakeRetriesExceeded,
|
|
994
957
|
typeof GuardActorRunnerFailed,
|
|
@@ -1016,7 +979,6 @@ export const RivetErrorReason: Schema.Union<
|
|
|
1016
979
|
OutgoingMessageTooLong,
|
|
1017
980
|
InvalidEncoding,
|
|
1018
981
|
InvalidRequest,
|
|
1019
|
-
GuardRequestTimeout,
|
|
1020
982
|
GuardActorReadyTimeout,
|
|
1021
983
|
GuardActorWakeRetriesExceeded,
|
|
1022
984
|
GuardActorRunnerFailed,
|
|
@@ -1146,8 +1108,6 @@ const reasonByCode: { [key: string]: MakeRivetErrorReason | undefined } = {
|
|
|
1146
1108
|
new OutgoingMessageTooLong({ cause: error }),
|
|
1147
1109
|
"encoding.invalid": (error) => new InvalidEncoding({ cause: error }),
|
|
1148
1110
|
"request.invalid": (error) => new InvalidRequest({ cause: error }),
|
|
1149
|
-
"guard.request_timeout": (error) =>
|
|
1150
|
-
new GuardRequestTimeout({ cause: error }),
|
|
1151
1111
|
"guard.actor_ready_timeout": (error) =>
|
|
1152
1112
|
new GuardActorReadyTimeout({ cause: error }),
|
|
1153
1113
|
"guard.actor_wake_retries_exceeded": (error) =>
|