Kadak

Errors

Structured, machine-readable Kadak errors with actionable fixes.

Errors

Kadak throws KadakError and provides payload helpers for APIs/agents:

import { toKadakErrorPayload } from '@shyk/kadak-orm'

try {
  await db.users.insert(payload)
} catch (error) {
  const body = toKadakErrorPayload(error)
  return res.status(400).json(body)
}

Payload shape:

{
  name: 'KadakError',
  code: 'VALIDATION_ERROR' | 'UNIQUE_VIOLATION' | ...,
  message: string,
  hint: string,
  table?: string,
  column?: string,
  constraint?: string,
}

UNIQUE_VIOLATION

When: Duplicate value inserted. Fix: Check existence before insert or update.

NOT_NULL_VIOLATION

When: Required field missing. Fix: Send the field, or mark column optional.

VALIDATION_ERROR

When: Input fails table validator. Fix: Run insertValidator().safeParse(payload) before query.

TABLE_NOT_FOUND

When: Target table does not exist. Fix: Run migrations and verify DATABASE_URL.

COLUMN_NOT_FOUND

When: Schema and DB columns are out of sync. Fix: Align table definition with real SQL columns.

CONNECTION_ERROR

When: DB is unreachable. Fix: Check URL, network, and Postgres status.

On this page