{"record":{"id":"aac24780b8655917","repo":"denoland/deno","slug":"deno-atomicoperation-is-not-a-promise-did-you-f","errorCode":null,"errorMessage":"'Deno.AtomicOperation' is not a promise: did you forget to call 'commit()'","messagePattern":"'Deno\\.AtomicOperation' is not a promise: did you forget to call 'commit\\(\\)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/kv/01_db.ts","lineNumber":596,"sourceCode":"      opts?.keysIfUndelivered ?? [],\n      opts?.backoffSchedule ?? null,\n    ]);\n    return this;\n  }\n\n  async commit(): Promise<Deno.KvCommitResult | Deno.KvCommitError> {\n    const versionstamp = await doAtomicWriteInPlace(\n      this.#rid,\n      this.#checks,\n      this.#mutations,\n      this.#enqueues,\n    );\n    if (versionstamp === null) return { ok: false };\n    return { ok: true, versionstamp };\n  }\n\n  then() {\n    throw new TypeError(\n      \"'Deno.AtomicOperation' is not a promise: did you forget to call 'commit()'\",\n    );\n  }\n\n  [SymbolFor(\"Deno.privateCustomInspect\")](inspect, inspectOptions) {\n    const operations = [];\n\n    // Format checks\n    for (let i = 0; i < this.#checks.length; ++i) {\n      const check = this.#checks[i];\n      const key = check[0];\n      const versionstamp = check[1];\n      const keyStr = inspect(key, inspectOptions);\n      const versionstampStr = versionstamp === null\n        ? \"null\"\n        : `\"${versionstamp}\"`;\n      ArrayPrototypePush(\n        operations,","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/kv/01_db.ts#L578-L614","documentation":"Deno.AtomicOperation is a builder, not a Promise. To make a forgotten commit() loud instead of a silent no-op, the class implements then() to throw TypeError(\"'Deno.AtomicOperation' is not a promise: did you forget to call 'commit()'\") whenever the object is awaited or otherwise then-ed. Only commit() executes the queued checks/mutations/enqueues and returns {ok:true, versionstamp} or {ok:false}.","triggerScenarios":"`await kv.atomic().set(k, v)` missing `.commit()`; returning the builder from an async function (implicit await); passing it to Promise.all(); calling `.then(...)` on the chain. The then() trap fires at await time, so the code fails before any write could be skipped silently.","commonSituations":"Chained-builder APIs invite awaiting the chain out of habit; refactors that split build and commit and dropped the terminal call; reviewers miss it because the line looks complete — without this guard the writes would silently never happen.","solutions":["Terminate every chain with commit(): const res = await kv.atomic().set(k, v).commit().","Check res.ok after commit — failed checks return {ok:false} rather than throwing.","Grep your codebase for 'atomic()' usages not followed by commit() on the same statement.","Wrap builder construction in small helper functions whose return type is the commit result, never the builder."],"exampleFix":"// before\nawait kv.atomic().set([\"a\"], 1); // then() throws: forgot to call 'commit()'\n\n// after\nconst res = await kv.atomic().set([\"a\"], 1).commit();\nif (!res.ok) throw new Error(\"atomic commit failed\");","handlingStrategy":"try-catch","validationCode":"function commit(op: Deno.AtomicOperation): Promise<Deno.KvCommitResult | Deno.KvCommitError> {\n  return op.commit(); // the ONLY correct terminal call\n}","typeGuard":"const isAtomicOperation = (v: unknown): v is Deno.AtomicOperation =>\n  v instanceof Deno.AtomicOperation;","tryCatchPattern":"try {\n  await op; // if someone forgot .commit(), then() throws\n} catch (e) {\n  if (e instanceof TypeError && e.message.includes(\"commit()\")) {\n    throw new Error(\"atomic chain never committed — append .commit()\");\n  }\n  throw e;\n}","preventionTips":["End every kv.atomic() chain with .commit() on the same statement","Check the returned {ok} flag after commit — failed checks do not throw","Write helper functions whose return type is the commit result, never the builder"],"tags":["deno-kv","atomic","promise","commit","builder-pattern"],"backgroundTag":"forgot-to-call-commit","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}