You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, transaction failures are terminal: if a transaction fails during persistence, it is marked as failed and rolled back immediately.
However, validation failures (e.g., missing fields, business logic rejections) are recoverable and should allow the user or application to correct inputs and retry without discarding the original transaction.
Without this distinction, user workflows involving iterative correction and submission become awkward and error-prone.
Proposed Solution
Extend the transaction state machine to explicitly differentiate between fatal and recoverable failures.
Updated Transaction States
pending: Transaction created but not yet persisted.
persisting: Transaction being sent to backend.
completed: Transaction successfully persisted.
failed_fatal: Non-recoverable error (e.g., network failure, unexpected server error). Transaction rolled back immediately.
failed_recoverable: Validation or business rule failure. Transaction paused, validation errors stored, eligible for manual retry.
Validation Error Storage
Validation errors are attached to the transaction metadata.
retry() reattempts persistence using the corrected local state.
abort() discards the transaction and rolls back optimistic changes.
Persist Function Responsibility
Developers may implement local validation inside persist() before sending network requests.
Developers can reject immediately inside persist() if validation fails, setting validation errors without network activity.
Problem
Currently, transaction failures are terminal: if a transaction fails during persistence, it is marked as
failed
and rolled back immediately.However, validation failures (e.g., missing fields, business logic rejections) are recoverable and should allow the user or application to correct inputs and retry without discarding the original transaction.
Without this distinction, user workflows involving iterative correction and submission become awkward and error-prone.
Proposed Solution
Extend the transaction state machine to explicitly differentiate between fatal and recoverable failures.
Updated Transaction States
pending
: Transaction created but not yet persisted.persisting
: Transaction being sent to backend.completed
: Transaction successfully persisted.failed_fatal
: Non-recoverable error (e.g., network failure, unexpected server error). Transaction rolled back immediately.failed_recoverable
: Validation or business rule failure. Transaction paused, validation errors stored, eligible for manual retry.Validation Error Storage
Validation errors are attached to the transaction metadata.
Shape:
Errors are replaced on each persist attempt.
Errors are read-only by default.
Developer API Additions
Transactions returned by
db.transaction()
will expose:retry()
reattempts persistence using the corrected local state.abort()
discards the transaction and rolls back optimistic changes.Persist Function Responsibility
Developers may implement local validation inside
persist()
before sending network requests.Developers can reject immediately inside
persist()
if validation fails, setting validation errors without network activity.Example:
Design Principles
Future Work
useTransaction(transactionId)
) to bind error states cleanly into forms.The text was updated successfully, but these errors were encountered: