rent
ReferenceRust API

Error handling

Generated operations return rent::runtime::EntityError. Preserve the source with ? unless the application can take a specific recovery action.

use rent::runtime::EntityError;

match client.user().email_eq(email).only().await {
    Ok(user) => show_profile(user),
    Err(EntityError::NotFound { .. }) => show_missing_profile(),
    Err(error) => return Err(error.into()),
}

Query and mutation invariants

ErrorMeaningTypical response
NotFoundonly() found no rowReturn absence or a domain-level not-found error
NotSingularonly() found several rowsFix the uniqueness or filter invariant
MissingRequiredFieldA create omitted required dataFix request validation or builder construction
InvalidConflictTargetAn upsert target is empty or unavailableUse a matching unique field or tuple
InvalidPageSizeA keyset page requested zero rowsReject or clamp the input
InvalidCursorA cursor is malformed or belongs to another keyReturn an invalid-pagination response
InvalidStreamBatchSizeA stream requested an empty batchChoose a positive bounded batch
SingleTargetRequiredA one-row operation has no explicit targetUse *_one(&entity) or .one(id)
InvalidCursorOrderingCursor pagination was combined with a conflicting order or an offsetRemove the order or offset, or choose a matching cursor
InvalidEagerBatchA relationship load cannot be split within the database parameter budgetLoad fewer parents per query or narrow the window
InvalidExtensionValueA generated extension field rejected an invalid typed valueValidate the value before building the mutation
MissingGeneratedIdThe backend did not return the generated identifier needed to reload a created entityCheck the identity column and backend configuration
BuilderSQL builder validation failed before executionFix the query shape the wrapped BuilderError names
FastPathMiddlewareA raw high-throughput path such as COPY cannot preserve configured policies, hooks, or codecsUse the ordinary builders for that entity

Model accessors such as post.author()? return a separate RelationNotLoaded error, not an EntityError, when the relationship was not eagerly loaded. Add the corresponding with_* call to the query.

Concurrency and transactions

OptimisticLock is an expected concurrency outcome: reload, merge, and retry only when the application's semantics allow it. VersionOverflow indicates an invalid long-lived version counter and should be treated as an invariant failure.

TransactionClosed, TransactionAlreadyActive, and TransactionsUnsupported report lifecycle misuse. TransactionRollback preserves both the operation error and rollback failure so neither is lost.

TransactionError<E> is used when a transaction closure returns an application-defined error. Its variants keep database and application failures distinct.

Driver and middleware errors

Driver wraps SQLx transport, server, decoding, cancellation, configuration, and argument errors. Check is_retryable_transaction() only around a complete idempotent transaction; do not retry arbitrary statements after an unknown partial outcome.

Policy, Intercept, and Hook identify the middleware layer that rejected an operation. FieldCodec identifies the entity, field, and encode/decode direction for encryption, blob, or custom storage failures.

NativeProjection identifies the model when a native selected value cannot be decoded. Inspect its source for the column/type mismatch, and check the schema against the live database. Retrying does not fix incompatible storage types. Dynamic projection decoding reports Decode or InvalidProjection instead.

Migration and extension commands expose their own typed plan, inspection, apply, directory, and registry errors. Their CLI messages include the failing file, object, extension, or operation whenever it is known.

On this page