# Problem code `'beforeCommit-threw'`

> Contract 2.0.0 · package sha256 `a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e` · generated from `configurator-runtime.d.ts`, `tables/problems.json` and `services/onsite-scripter/scripts/contract-docs-what-to-do.json` by `services/onsite-scripter/scripts/build-contract-docs.mjs`; edit the source, not this file.

A member of [`ProblemCode`](../api/ProblemCode.md) · stable · since 2.0.0

A [`beforeCommit`](../api/Session.beforeCommit.md) function threw, or was pending after 10 s; its writes were undone.

## What to do

Fix the cause in your [`session.beforeCommit`](../api/Session.beforeCommit.md) function (the Problem's `message` has it) and make it settle within 10 s: a throw, or a function still pending then, undoes only that function's own writes and the commit goes on without them. Let a failure escape rather than catch it half-way, which would keep the half-done writes, or catch it and write a complete fallback layout. The hook is labs: register it through [`has(session, 'beforeCommit')`](../api/has.md) ([`has`](../api/has.md) from the package root) with an [`on('committed')`](../api/Session.on.md) fallback, as below.

```ts
has(session, 'beforeCommit') // either branch unregisters when `signal` aborts
  ? session.beforeCommit('layout', async (commit) => {
      try { await layout(commit.tx); } catch { await fallbackLayout(commit.tx); } // every node posed either way
    }, { signal })
  // keep this branch: a runtime without the labs hook gets the same writes, one frame later
  : session.on('committed', ({ recorded }) => { if (recorded) void layout(session); }, { signal });
```

## Where the declaration names it

- [`Session.beforeCommit`](../api/Session.beforeCommit.md): A throw undoes only its own writes, object by object as a savepoint's (spec section 6.1, O7), and records 'beforeCommit-threw'; the commit proceeds.

The set is open: handle a code you don't know (`'other'`).

## Recorded by

- the table row `failure-matrix/cases/before-commit-throws` (`tables/failure-matrix.json`)
- the table row `hold/cases/case-5` (`tables/hold.json`)
