@@ -2,5 +2,192 @@ import { isType } from '@ballerine/common';
22import { PrismaClientKnownRequestError } from '@prisma/client/runtime' ;
33import { z } from 'zod' ;
44
5+ const ALL_PRISMA_ERROR_CODES = [
6+ // Authentication failed
7+ 'P1000' ,
8+ // Unable to connect to database
9+ 'P1001' ,
10+ // Database server connection timed out
11+ 'P1002' ,
12+ // Database does not exist
13+ 'P1003' ,
14+ // Operations timed out
15+ 'P1008' ,
16+ // Database already exists
17+ 'P1009' ,
18+ // User access denied
19+ 'P1010' ,
20+ // Error starting transaction
21+ 'P1011' ,
22+ // Validation error
23+ 'P1012' ,
24+ // Preview feature not enabled
25+ 'P1013' ,
26+ // Underlying kind mismatch
27+ 'P1014' ,
28+ // Prisma extension error
29+ 'P1015' ,
30+ // Engine data loading error
31+ 'P1016' ,
32+ // Server closed connection
33+ 'P1017' ,
34+
35+ // Query Engine (P2xxx) - Query execution and data validation errors
36+ // Input value too long
37+ 'P2000' ,
38+ // Record does not exist
39+ 'P2001' ,
40+ // Unique constraint violation
41+ 'P2002' ,
42+ // Foreign key constraint violation
43+ 'P2003' ,
44+ // Constraint violation
45+ 'P2004' ,
46+ // Value invalid for type
47+ 'P2005' ,
48+ // Field value null violation
49+ 'P2006' ,
50+ // Data validation error
51+ 'P2007' ,
52+ // Failed to parse query
53+ 'P2008' ,
54+ // Failed to validate query
55+ 'P2009' ,
56+ // Raw query error
57+ 'P2010' ,
58+ // Null constraint violation
59+ 'P2011' ,
60+ // Missing required value
61+ 'P2012' ,
62+ // Missing required argument
63+ 'P2013' ,
64+ // Change violates relation
65+ 'P2014' ,
66+ // Related record not found
67+ 'P2015' ,
68+ // Query interpretation error
69+ 'P2016' ,
70+ // Records not connected
71+ 'P2017' ,
72+ // Required connected records not found
73+ 'P2018' ,
74+ // Input error
75+ 'P2019' ,
76+ // Value out of range
77+ 'P2020' ,
78+ // Table does not exist
79+ 'P2021' ,
80+ // Column does not exist
81+ 'P2022' ,
82+ // Inconsistent column data
83+ 'P2023' ,
84+ // Query execution timed out
85+ 'P2024' ,
86+ // Operation failed
87+ 'P2025' ,
88+ // Unsupported feature
89+ 'P2026' ,
90+ // Multiple errors
91+ 'P2027' ,
92+ // Transaction API error
93+ 'P2028' ,
94+ // Query batch error
95+ 'P2029' ,
96+ // Explicit transaction required
97+ 'P2030' ,
98+ // Transaction rolled back
99+ 'P2031' ,
100+ // Number out of range
101+ 'P2033' ,
102+ // Transaction timeout
103+ 'P2034' ,
104+ // Invalid transaction state
105+ 'P2035' ,
106+ // Transaction rollback error
107+ 'P2036' ,
108+ // Transaction commit error
109+ 'P2037' ,
110+
111+ // Schema Engine (P3xxx) - Schema and migration errors
112+ // Failed to create database
113+ 'P3000' ,
114+ // Migration possible data loss
115+ 'P3001' ,
116+ // Migration required
117+ 'P3002' ,
118+ // Migration format error
119+ 'P3003' ,
120+ // Migration create error
121+ 'P3004' ,
122+ // Migration apply error
123+ 'P3005' ,
124+ // Migration name required
125+ 'P3006' ,
126+ // Migration already exists
127+ 'P3007' ,
128+ // Migration not found
129+ 'P3008' ,
130+ // Migrate command error
131+ 'P3009' ,
132+ // Migration squash error
133+ 'P3010' ,
134+ // Migration rolled back
135+ 'P3011' ,
136+ // Missing migration file
137+ 'P3012' ,
138+ // Conflicting migrations
139+ 'P3013' ,
140+ // Migrations list error
141+ 'P3014' ,
142+ // Could not find migration
143+ 'P3015' ,
144+ // Migration verification error
145+ 'P3016' ,
146+ // Migration execution error
147+ 'P3017' ,
148+ // Migration manifest error
149+ 'P3018' ,
150+ // Migration script error
151+ 'P3019' ,
152+ // Migration history error
153+ 'P3020' ,
154+ // Migration history conflict
155+ 'P3021' ,
156+ // Failed to parse schema
157+ 'P3022' ,
158+
159+ // DB Pull (P4xxx) - Database introspection errors
160+ // Introspection error
161+ 'P4000' ,
162+ // Detection conflict
163+ 'P4001' ,
164+ // Introspection validation error
165+ 'P4002' ,
166+
167+ // Accelerate (P5xxx/P6xxx) - Performance and optimization errors
168+ // Invalid connection string
169+ 'P5011' ,
170+ // Engine version mismatch
171+ 'P6000' ,
172+ // Migration pending
173+ 'P6001' ,
174+ // Engine not started
175+ 'P6002' ,
176+ // Engine timeout
177+ 'P6003' ,
178+ // Engine crashed
179+ 'P6004' ,
180+ // Engine not found
181+ 'P6005' ,
182+ // Engine start error
183+ 'P6006' ,
184+ // Engine protocol error
185+ 'P6008' ,
186+ // Engine file error
187+ 'P6009' ,
188+ // Engine binary error
189+ 'P6010'
190+ ] as const ;
191+
5192export const isPrismaException = ( value : unknown ) : value is PrismaClientKnownRequestError =>
6- isType ( z . object ( { code : z . string ( ) } ) ) ( value ) ;
193+ isType ( z . object ( { code : z . enum ( ALL_PRISMA_ERROR_CODES ) } ) ) ( value ) ;
0 commit comments