Skip to content
clientdb

Search the docs

Find a page or section

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.

CodeMeaningFix
Forbiddena 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 oneonly viewers who can read a restricted field may change it, or name it in an update
ReadOnlythe session is read-only: the route says readOnly: true, the session callback returned readOnly: true, or the session is anonymousexpected; the client's write methods throw ReadOnlyError before sending
Validationan 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 refusedfix the input; the message names the field, or for database constraints the operation and model
Conflicta 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 atuse a new id or value, or delete or re-point the referencing rows
NotFoundan 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
AccessLostthe 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
SchemaOutdatedthe device's schema differs from the server'sreload the app
Stalea resend the server may have applied already, after retention.transactions deleted its id: the device kept trying to send it, unconfirmed, for longer than thatexpected after very long offline periods; raise retention.transactions to make it rarer

Client errors

ErrorWhenFix
ReadOnlyErrora 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
SyncRequestErrorthe 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 sessionsign 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 querylist the field and operator in the model's query rules
SchemaOutdatedErrora bootstrap or pull reports another schema hash; db.$status becomes "outdated"reload; ship clients and server together
ProtocolMismatchthe server speaks another protocol versionreload
TransactionErrorhandle.confirmed of a refused transaction; rejection holds the code and messagesee Rejection codes
createDatabaseClient: url "…" is relative and there is no page location to resolve it againsta relative url outside a browser (tests, Node, React Native)pass an absolute URL
useLive is not used with MobX reactivityuseLive inside a client using mobxReactivityuse observer() (or live()) and read directly

Server errors

ErrorWhenFix
AccessCompileErrora read rule can't be routed, at engine creationsee What the compiler rejects
AccessCompileError (no viewer condition)a read branch like todo.isPrivate.is(false) alone would show rows to every signed-in userwrite $.and($.authenticated, …), or $.public to include anonymous visitors
401your session callback returned null, and the route doesn't set anonymous: truecheck the session cookie or bearer token; the server reads ?token= only on WebSocket upgrades, so HTTP requests send Authorization: Bearer
415a POST whose body isn't Content-Type: application/json; clientdb's clients always send itsend JSON with that header. Other media types are refused so other sites can't post forms with the viewer's cookies
403 on the WebSocketa 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 allowsserve 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 characterstokens.secret or verifyJwt({ secret }) is short enough to guess from a tokengenerate one with openssl rand -base64 32
403 / 400 on POST /query (QueryError)a query outside the model's query rules, or malformedsee the client's SyncRequestError above
503 with code NotMigratedclientdb: 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 rulesrun 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 reconnecttransient 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 onlya session or server write names a tenant while the engine serves Prisma-managed tableskeep 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 versionre-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 ruleadd 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 modelrules use $.viewer, but no model is named user and createSchema / fromPrisma has no viewer optionname the model whose rows are users with viewer
Schema changed without a migration: …engine-owned tables, and the schema changed with no versioned migrationadd a migration(…) (see Migrations)
engine.migrate() needs a direct database connectionthe database URL goes through a transaction pooler and DIRECT_URL isn't setset 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 emptypass database or set the variable
createEngine: retention.log must be at least "1h"a shorter log retentionprocesses following the log need at least an hour
createEngine: retention.transactions must be at least retention.logtransaction ids kept for less time than the logkeep them at least as long, so a device the log can still catch up resends safely
fromPrisma errorsunsupported 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 functionsomit 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):

Text
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):

Text
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.

Text
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:

Text
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):

Text
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):

Text
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.