Use tagged errors in tests

This commit is contained in:
elpresidank 2026-06-04 08:10:09 -05:00
parent c4500f216e
commit c48927b7c5
8 changed files with 104 additions and 23 deletions

View file

@ -1,6 +1,7 @@
import { describe, expect, it } from "@effect/vitest";
import { ConfigProvider, Effect, Fiber } from "effect";
import * as EffectChunk from "effect/Chunk";
import * as S from "effect/Schema";
import {
MessagingRuntimeLive,
PubSub,
@ -18,6 +19,13 @@ import {
import { ChunkingService } from "../chunking/service.js";
import { recursiveSplit } from "../chunking/recursive-splitter.js";
class WaitForTimeout extends S.TaggedErrorClass<WaitForTimeout>()(
"WaitForTimeout",
{ label: S.String },
) {}
const isWaitForTimeout = S.is(WaitForTimeout);
function createMessage<T>(value: T, properties: Record<string, string> = {}): Message<T> {
return {
value: () => value,
@ -36,14 +44,14 @@ const waitFor = (condition: () => boolean, label: string) =>
return;
}
if (Date.now() > deadline) {
reject(new Error(`Timed out waiting for ${label}`));
reject(WaitForTimeout.make({ label }));
return;
}
setTimeout(check, 5);
};
check();
}),
catch: (error) => error,
catch: (error) => isWaitForTimeout(error) ? error : WaitForTimeout.make({ label }),
});
class RecordingProducer<T> implements BackendProducer<T> {