MCPcopy
hub / github.com/prisma/prisma / mapDriverError

Function mapDriverError

packages/adapter-mariadb/src/errors.ts:16–143  ·  view source on GitHub ↗
(error: DriverError)

Source from the content-addressed store, hash-verified

14}
15
16export function mapDriverError(error: DriverError): MappedError {
17 switch (error.errno) {
18 case 1062: {
19 const index = error.sqlMessage?.split(' ').pop()?.split("'").at(1)?.split('.').pop()
20 return {
21 kind: 'UniqueConstraintViolation',
22 constraint: index !== undefined ? { index } : undefined,
23 }
24 }
25
26 case 1451:
27 case 1452: {
28 const field = error.sqlMessage?.split(' ').at(17)?.split('`').at(1)
29 return {
30 kind: 'ForeignKeyConstraintViolation',
31 constraint: field !== undefined ? { fields: [field] } : undefined,
32 }
33 }
34
35 case 1263: {
36 const index = error.sqlMessage?.split(' ').pop()?.split("'").at(1)
37 return {
38 kind: 'NullConstraintViolation',
39 constraint: index !== undefined ? { index } : undefined,
40 }
41 }
42
43 case 1264:
44 return {
45 kind: 'ValueOutOfRange',
46 cause: error.sqlMessage ?? 'N/A',
47 }
48
49 case 1364:
50 case 1048: {
51 const field = error.sqlMessage?.split(' ').at(1)?.split("'").at(1)
52 return {
53 kind: 'NullConstraintViolation',
54 constraint: field !== undefined ? { fields: [field] } : undefined,
55 }
56 }
57
58 case 1049: {
59 const db = error.sqlMessage?.split(' ').pop()?.split("'").at(1)
60 return {
61 kind: 'DatabaseDoesNotExist',
62 db,
63 }
64 }
65
66 case 1007: {
67 const db = error.sqlMessage?.split(' ').at(3)?.split("'").at(1)
68 return {
69 kind: 'DatabaseAlreadyExists',
70 db,
71 }
72 }
73

Callers 1

convertDriverErrorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected