Reference
Errors and warnings
Every error code and development warning clientdb produces, what it means and how to fix it.
Rejection codes
A transaction the server refuses is dropped from the device's pending changes (they disappear from the screen), handle.confirmed rejects with a TransactionError, db.$onTransactionError listeners and the onTransactionError option are called, and the transaction leaves the undo history. On the server, hooks.onWriteRejected receives the session, code, model, operation and failed branches.
| Code | Meaning | Fix |
|---|---|---|
Forbidden | a write rule refused it; the message names the branches that failed, e.g. Forbidden: todo.delete (author: no, admin: no), or for an update the fields no group allows (todo.update isPrivate (not in any update group)) | check the model's create, update, delete or archive rule; when must hold before and after an update |
Forbidden (enforce) | todo.authorId must equal the viewer's id (got "…") | send the enforced value from the device: authorId: db.$session.viewerId |
Forbidden (restricted field) | project.update inviteCode (the viewer can't read it), even when the value sent is the stored one | only viewers who can read a restricted field may change it, or name it in an update |
ReadOnly | the session is read-only: the route says readOnly: true, the session callback returned readOnly: true, or the session is anonymous | expected; the client's write methods throw ReadOnlyError before sending |
Validation | an unknown field or model, a missing required field, a value that doesn't fit the field (todo.done must be a boolean (got "yes"): the wrong type, a value outside an enum, or null in a field that isn't nullable), a validate() message, a generated field, a changed primary key, or a value a database constraint refused | fix the input; the message names the field, or for database constraints the operation and model |
Conflict | a create with an existing id, a value another row already holds in a unique field, or a delete of a row that restrict relations still point at | use a new id or value, or delete or re-point the referencing rows |
NotFound | an update or delete of a row that doesn't exist, or that the viewer can't read (refused alike) | the row was deleted meanwhile, or the viewer lost access to it |
AccessLost | the device lost read access to a row it had unsent changes on (issued on the device; the whole transaction is refused, including its changes to rows it still reads) | expected after a demotion or removal; redo the changes that still apply |
SchemaOutdated | the device's schema differs from the server's | reload the app |
Stale | a resend the server may have applied already, after retention.transactions deleted its id: the device kept trying to send it, unconfirmed, for longer than that | expected after very long offline periods; raise retention.transactions to make it rarer |
Client errors
| Error | When | Fix |
|---|---|---|
ReadOnlyError | a write on a read-only client: This client is read-only (createDatabaseClient({ readOnly: true })), (anonymous session) or (the server's session is read-only) | check db.$session.readOnly before showing write controls |
SyncRequestError | the server answered a sync request with an error status; status holds it, and unauthorized is true for 401 and 403. db.$ready() rejects with it when the server refuses the session | sign in again; for other statuses the client retries |
SyncRequestError from query() | query failed: 403 Forbidden: todo.title isn't queryable: list it in todo's query.fields, or 400 Validation for a limit over maxLimit or a malformed query | list the field and operator in the model's query rules |
SchemaOutdatedError | a bootstrap or pull reports another schema hash; db.$status becomes "outdated" | reload; ship clients and server together |
ProtocolMismatch | the server speaks another protocol version | reload |
TransactionError | handle.confirmed of a refused transaction; rejection holds the code and message | see Rejection codes |
createDatabaseClient: url "…" is relative and there is no page location to resolve it against | a relative url outside a browser (tests, Node, React Native) | pass an absolute URL |
useLive is not used with MobX reactivity | useLive inside a client using mobxReactivity | use observer() (or live()) and read directly |
Server errors
| Error | When | Fix |
|---|---|---|
AccessCompileError | a read rule can't be routed, at engine creation | see What the compiler rejects |
AccessCompileError (no viewer condition) | a read branch like todo.isPrivate.is(false) alone would show rows to every signed-in user | write $.and($.authenticated, …), or $.public to include anonymous visitors |
401 | your session callback returned null, and the route doesn't set anonymous: true | check the session cookie or bearer token; the server reads ?token= only on WebSocket upgrades, so HTTP requests send Authorization: Bearer |
415 | a POST whose body isn't Content-Type: application/json; clientdb's clients always send it | send JSON with that header. Other media types are refused so other sites can't post forms with the viewer's cookies |
403 on the WebSocket | a page on another origin opened it with the viewer's cookies: without cors, other origins need a sync token, and with cors, an origin it allows | serve the page from the sync server's origin, add the page's origin to cors, or use sync tokens |
…: the secret must be at least 32 characters | tokens.secret or verifyJwt({ secret }) is short enough to guess from a token | generate one with openssl rand -base64 32 |
403 / 400 on POST /query (QueryError) | a query outside the model's query rules, or malformed | see the client's SyncRequestError above |
503 with code NotMigrated | clientdb: refusing to serve clients: …. Run \await engine.migrate()` (e.g. in your deploy step) and retry.The route refuses to serve untilengine.migrate()` has run against the current schema and rules | run npx clientdb migrate in your deploy step; after upgrading clientdb, run npx clientdb-prisma models and migrate first |
503 with code Unavailable (Unavailable) | the database failed in a way a retry can fix (lost connection, shutdown, timeout, contention), or another process's migrate() switched the database to other rules or another schema than this process was built with. Nothing was refused: clients keep their writes and retry, and live sockets close with code 1011 and reconnect | transient errors need nothing; a process still running the previous release keeps answering this until it is replaced |
clientdb: refusing tenant "…": external tables hold the rows of the default tenant only | a session or server write names a tenant while the engine serves Prisma-managed tables | keep tenant out of sessions, or serve tenants with engine-owned tables |
… has no field_readers column: replace the clientdb models in schema.prisma with the current \npx clientdb-prisma models`` | clientdb's tables predate this version | re-run npx clientdb-prisma models, then prisma migrate |
fromPrisma: User.apiToken looks secret … | a synced column's name matches token, secret, hash, password, salt or key, and is in none of omit, models.<Model>.restricted or notSecret (also a type error) | omit keeps it on the server, restricted sends it only where a field rule allows, notSecret sends it to every reader |
models.Project.archivable: Project can't be archivable without the columns archivedAt DateTime? and archivedBy String? | an archivable Prisma model lacks the columns (also a type error) | add them to schema.prisma |
definePermissions: no read rule for … | outside production, a synced model has no read rule | add defineModelRules(schema, "model", { read: … }) ($.canRead(row.parent) to read like its parent), or mark the model serverOnly if it never syncs |
…: the schema has no viewer model | rules use $.viewer, but no model is named user and createSchema / fromPrisma has no viewer option | name the model whose rows are users with viewer |
Schema changed without a migration: … | engine-owned tables, and the schema changed with no versioned migration | add a migration(…) (see Migrations) |
engine.migrate() needs a direct database connection | the database URL goes through a transaction pooler and DIRECT_URL isn't set | set DIRECT_URL (or the directUrl option) to the direct URL |
createEngine: pass \database` (a Postgres URL or a pg.Pool), or set DATABASE_URL` | no database option and DATABASE_URL is empty | pass database or set the variable |
createEngine: retention.log must be at least "1h" | a shorter log retention | processes following the log need at least an hour |
createEngine: retention.transactions must be at least retention.log | transaction ids kept for less time than the log | keep them at least as long, so a device the log can still catch up resends safely |
fromPrisma errors | unsupported Prisma shapes, named in the message: ids that aren't String, composite foreign keys, @map on enum values, Bytes and other unsupported types, unknown @default functions | omit the field or exclude the model |
Development warnings
Unhandled rejections (every rejection nobody handles; in production only Forbidden, Validation, Stale and AccessLost, which the device issues itself):
clientdb: the server rejected a transaction (Forbidden: todo.delete (author: no, admin: no)); its optimistic changes were undone.Handle them with useTransactionErrors, db.$onTransactionError or the onTransactionError option, or await confirmed. See Transactions.
Untracked reads during render (@clientdb/react, once per model.property):
clientdb: todo.title read during render outside useLive()/live(); this component won't update when it changes. Read it inside useLive(() => …), or wrap the component in live() (observer() with MobX).See Reactivity.
Mismatched computed / effect (once): an effect or computed from @clientdb/client read data of a client that uses MobX reactivity.
clientdb: an effect() or computed() from @clientdb/client read data of a client that uses mobx reactivity, so it won't re-run when that data changes. Use db.$computed() and db.$effect(), which follow the client's reactivity.See Reactivity.
Untracked rows and missing triggers (clientdbHandler, createFetchHandler and createSyncServer, first request, unless NODE_ENV is production or warnUntracked: false). With the change triggers installed neither occurs:
clientdb: 3 todo rows are not tracked (written outside clientdb, e.g. by a seed script), so clients never receive them. Run engine.migrate() (or engine.reconcile()) to sync them, and capture future writes with the triggers from `npx clientdb-prisma triggers`.
clientdb: writes to Tag made outside clientdb (Prisma Client, SQL) won't reach clients: their tables have no clientdb capture triggers. Save the output of `npx clientdb-prisma triggers` as a migration, or call engine.changed() after such writes.See Writes made outside clientdb.
anonymous and the rules disagree (the handler, outside production):
clientdb: some read rules use $.public, but this handler answers signed-out requests with 401, so nobody signed out sees those rows. Pass `anonymous: true` to serve them.Large bootstraps (once per user, above bootstrapRowWarning, default 20,000 rows):
clientdb: a bootstrap for viewer u_42 sent 31,200 eager rows (todo: 28,000, comment: 3,200). Make large models lazy, or raise bootstrapRowWarning.See Load modes.
verifyJwt without audience (outside production): a JWKS-verified token without an audience check accepts tokens your auth provider issued for your other apps. Pass the audience your app's tokens carry.