MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / isUniqueViolation

Function isUniqueViolation

packages/core/sdk/src/fuma-runtime.ts:37–58  ·  view source on GitHub ↗
(cause: unknown)

Source from the content-addressed store, hash-verified

35>;
36
37const isUniqueViolation = (cause: unknown): boolean => {
38 let current = cause;
39 for (let i = 0; i < 5; i += 1) {
40 const err =
41 current && typeof current === "object" ? (current as Record<string, unknown>) : null;
42 if (!err) return false;
43 const code = err["code"];
44 // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: database drivers expose unique-violation details on native error messages
45 const message = err["message"];
46 const innerCause = err["cause"];
47 if (code === "23505") return true;
48 if (
49 typeof message === "string" &&
50 /unique constraint|duplicate key|violates unique constraint/i.test(message)
51 ) {
52 return true;
53 }
54 if (!innerCause || innerCause === current) return false;
55 current = innerCause;
56 }
57 return false;
58};
59
60const causeMessage = (cause: unknown): string | undefined => {
61 const message =

Callers 1

fumaFailureFromCauseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected