From c3c61894d2b119ae424bac605d4b3099e0b674e5 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 18 Oct 2026 21:47:21 +0200 Subject: fix: report a duplicate name instead of failing the page Adding a category or project whose name exists, or renaming an item onto an existing name, hit the unique constraint and rendered SvelteKit's 500 page. Translate SQLITE_CONSTRAINT_UNIQUE into a form error on the three forms. --- src/lib/server/db/errors.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/lib/server/db/errors.ts (limited to 'src/lib/server/db/errors.ts') diff --git a/src/lib/server/db/errors.ts b/src/lib/server/db/errors.ts new file mode 100644 index 0000000..4b101f8 --- /dev/null +++ b/src/lib/server/db/errors.ts @@ -0,0 +1,13 @@ +/** + * True when the failure is SQLite's UNIQUE constraint. Drizzle wraps driver + * errors, so the libsql error sits at some depth of the `cause` chain. + */ +export function isUniqueViolation(error: unknown): boolean { + let current: unknown = error; + while (current instanceof Error) { + if ('code' in current && current.code === 'SQLITE_CONSTRAINT_UNIQUE') + return true; + current = current.cause; + } + return false; +} -- cgit v1.3