Open History to see the last commit
1import { Schema, SchemaIssue } from "effect";
2
3// ===============================
4// Core Persistence Errors
5// ===============================
6
7export class PersistenceSqlError extends Schema.TaggedErrorClass<PersistenceSqlError>()(
8 "PersistenceSqlError",
9 {
10 operation: Schema.String,
11 detail: Schema.String,
12 cause: Schema.optional(Schema.Defect),
13 },
14) {
15 override get message(): string {
16 return `SQL error in ${this.operation}: ${this.detail}`;
17 }
18}
19
20export class PersistenceDecodeError extends Schema.TaggedErrorClass<PersistenceDecodeError>()(
21 "PersistenceDecodeError",
22 {
23 operation: Schema.String,
24 issue: Schema.String,
25 cause: Schema.optional(Schema.Defect),
26 },
27) {
28 override get message(): string {
29 return `Decode error in ${this.operation}: ${this.issue}`;
30 }
31}
32
33export function toPersistenceSqlError(operation: string) {
34 return (cause: unknown): PersistenceSqlError =>
35 new PersistenceSqlError({
36 operation,
37 detail: `Failed to execute ${operation}`,
38 cause,
39 });
40}
41
42export function toPersistenceDecodeError(operation: string) {
43 return (error: Schema.SchemaError): PersistenceDecodeError =>
44 new PersistenceDecodeError({
45 operation,
46 issue: SchemaIssue.makeFormatterDefault()(error.issue),
47 cause: error,
48 });
49}
50
51export function toPersistenceDecodeCauseError(operation: string) {
52 return (cause: unknown): PersistenceDecodeError =>
53 new PersistenceDecodeError({
54 operation,
55 issue: `Failed to execute ${operation}`,
56 cause,
57 });
58}
59
60export const isPersistenceError = (u: unknown) =>
61 Schema.is(PersistenceSqlError)(u) || Schema.is(PersistenceDecodeError)(u);
62
63// ===============================
64// Provider Session Repository Errors
65// ===============================
66
67export class ProviderSessionRepositoryValidationError extends Schema.TaggedErrorClass<ProviderSessionRepositoryValidationError>()(
68 "ProviderSessionRepositoryValidationError",
69 {
70 operation: Schema.String,
71 issue: Schema.String,
72 cause: Schema.optional(Schema.Defect),
73 },
74) {
75 override get message(): string {
76 return `Provider session repository validation failed in ${this.operation}: ${this.issue}`;
77 }
78}
79
80export class ProviderSessionRepositoryPersistenceError extends Schema.TaggedErrorClass<ProviderSessionRepositoryPersistenceError>()(
81 "ProviderSessionRepositoryPersistenceError",
82 {
83 operation: Schema.String,
84 detail: Schema.String,
85 cause: Schema.optional(Schema.Defect),
86 },
87) {
88 override get message(): string {
89 return `Provider session repository persistence error in ${this.operation}: ${this.detail}`;
90 }
91}
92
93export type OrchestrationEventStoreError = PersistenceSqlError | PersistenceDecodeError;
94
95export type ProviderSessionRepositoryError =
96 | ProviderSessionRepositoryValidationError
97 | ProviderSessionRepositoryPersistenceError;
98
99export type OrchestrationCommandReceiptRepositoryError =
100 | PersistenceSqlError
101 | PersistenceDecodeError;
102
103export type ProviderSessionRuntimeRepositoryError = PersistenceSqlError | PersistenceDecodeError;
104
105export type ProjectionRepositoryError = PersistenceSqlError | PersistenceDecodeError;