Skip to content

refactor(db): one check for a refused conditional write - #658

Merged
alukach merged 2 commits into
mainfrom
refactor/conditional-check-failed
Oct 13, 2026
Merged

alukach merged 2 commits into
mainfrom
refactor/conditional-check-failed

Conversation

@alukach

@alukach alukach commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Seven places checked by hand whether a DynamoDB write was refused by its ConditionExpression, in three spellings (error instanceof Error && error.name === …, (error as { name?: string })?.name === …, and a local isConcurrentEdit). They now call isConditionalCheckFailed from src/lib/clients/database/errors.ts:

  • clients/database: accounts.ts, account-trusts.ts, data-connections.ts, products.ts
  • actions: account.ts, service-accounts.ts, product-mirrors.ts (isConcurrentEdit stays as a name for what the failure means there)

The helper matches by name, as every copy did, so it also holds for the plain errors tests throw. It's in its own module rather than re-exported from @/lib/clients, because several action tests mock that module with a factory and would otherwise get undefined.

actions/data-connections.ts still has its own two copies. #657 rewrites that file and replaces them with one in operations/data-connections.ts, which will switch to this helper once this merges. Leaving the file alone here keeps the two PRs from conflicting.

Docs and ADRs

No behavior change, so no docs, ADR or llms.txt line is affected.

Testing

  • npm run type-check passes.
  • The full jest suite passes: 87 suites, 899 tests. The existing tests for duplicate accounts, service-account ids, data-connection upserts and concurrent mirror edits throw ConditionalCheckFailedException-named errors through these paths.

🤖 Generated with Claude Code

Seven hand-written tests of `error.name === "ConditionalCheckFailedException"`, in three different spellings, become `isConditionalCheckFailed` in src/lib/clients/database/errors.ts. It lives in its own module so that tests mocking the table clients still get the real check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
source-coop-ui Ready Ready Preview Oct 13, 2026 7:05pm UTC
source-cooperative Ready Ready Preview Oct 13, 2026 7:05pm UTC

Request Review

@claude

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @alukach's task in 16s —— View job


✅ No blocking issues — safe to merge.

(The PR is already merged.) I read the final state of the call sites. isConditionalCheckFailed in src/lib/clients/database/errors.ts matches by name and tolerates null and undefined. It is equivalent to all three spellings it replaced, so there is no behavior change. Keeping it out of the @/lib/clients barrel is sound, given the factory mocks.

Docs

No docs, ADR or llms.txt page is affected. The PR description says so explicitly, which meets the CLAUDE.md requirement.

Simplify (ponytail)

  • src/lib/actions/product-mirrors.ts: the local isConcurrentEdit alias is now a thin wrapper, if it still exists as a function. Inline isConditionalCheckFailed at the call sites, or keep the alias only if the name carries real meaning. Four call sites already use the helper directly.
  • src/lib/actions/data-connections.ts:161,286: two hand-rolled copies remain. The PR description says feat(api): data connections, including account-owned ones #657 will fold them in, so no action is needed here.

💰 Estimated review cost: $0.12 · 0m15s · 6 turns

Replaced usage of 'isConcurrentEdit' with 'isConditionalCheckFailed' for error handling in addProductMirror function.
@alukach
alukach marked this pull request as ready for review October 13, 2026 19:03
@alukach
alukach merged commit 9552a84 into main Oct 13, 2026
7 of 9 checks passed
@alukach
alukach deleted the refactor/conditional-check-failed branch October 13, 2026 19:03

This branch was successfully deployed

2 active deployments
Preview – source-cooperative — a1dd4d93 Deployed Oct 13, 2026 by vercel[bot]
Preview – source-coop-ui — a1dd4d93 Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant