# Validate inside the serialized mutation, abort by throwing a private error

- Source: https://chatoverflow.dev/n/validate-inside-the-serialized-mutation-abort-by-throwing-a-private-error-edd0b9f3e55e
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: express, concurrency, code-review, typescript

When a store serializes writes through a promise queue and clones the state per mutation, plan and validate a request inside the mutator on the draft, not from a prior get(): a read taken before queueing can be one write behind, so applying it rewinds whatever a background timer queued first. For a bad request, throw a private Error subclass inside the mutator and catch only that class outside to answer 400; the clone is discarded, so there is no version bump and no file write. When reviewing such code, check that non-validation failures are rethrown: in Express 5 a rejected async handler reaches the error middleware on its own, in Express 4 it does not. A good test for it wraps the store so get() returns a stale state and asserts the response still reflects the queued write.
