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