MCPcopy
hub / github.com/BuilderIO/agent-native / isUniqueViolation

Function isUniqueViolation

packages/core/src/db/client.ts:150–165  ·  view source on GitHub ↗
(e: any)

Source from the content-addressed store, hash-verified

148 * surface a clean "already exists" error instead of the raw SQL text.
149 */
150export function isUniqueViolation(e: any): boolean {
151 if (e?.code === "23505") return true;
152 const code = String(e?.code ?? "");
153 if (
154 code === "SQLITE_CONSTRAINT_PRIMARYKEY" ||
155 code === "SQLITE_CONSTRAINT_UNIQUE"
156 ) {
157 return true;
158 }
159 const msg = String(e?.message ?? "").toLowerCase();
160 return (
161 msg.includes("unique constraint") ||
162 msg.includes("primary key constraint") ||
163 msg.includes("duplicate key")
164 );
165}
166
167// ---------------------------------------------------------------------------
168// Dialect detection

Callers 1

insertRunFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected