Skip to content

fix(platform): throw ConvexError for vendor not-found and conflict cases (#2004) - #2209

Merged
yannickmonney merged 1 commit into
mainfrom
tale/xs7dx3z8e1mvk5yyt5f9s7basn89e7hq
Jun 29, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
tale/xs7dx3z8e1mvk5yyt5f9s7basn89e7hq

Conversation

@larryro

@larryro larryro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves the remaining raw Error throws in the vendors mutations (not-found guards and update/delete duplicate-conflict checks) that caused opaque 500s in both the UI and REST API paths.

Issue #1993 covered the duplicate-add case on createVendor; this PR covers the not-found and update/delete conflict cases that were left out.

Changes

  • services/platform/convex/vendors/mutations.ts (client-callable mutationWithRLS): replaced throw new Error(...) with structured ConvexError:
    • updateVendor not-found → ConvexError({ code: 'VENDOR_NOT_FOUND' })
    • updateVendor email conflict → ConvexError({ code: 'DUPLICATE_EMAIL' })
    • updateVendor externalId conflict → ConvexError({ code: 'DUPLICATE_EXTERNAL_ID' })
    • deleteVendor not-found → ConvexError({ code: 'VENDOR_NOT_FOUND' })
  • services/platform/convex/vendors/internal_mutations.ts (REST path via withRestAuth): same conversions for updateVendor (incl. cross-tenant guard) and deleteVendor (incl. cross-tenant guard).
  • services/platform/convex/lib/rest/helpers.ts: extended httpStatusForConvexCode so withRestAuth maps VENDOR_NOT_FOUND → 404, DUPLICATE_EMAIL → 409, DUPLICATE_EXTERNAL_ID → 409 instead of falling through to 500.
  • services/platform/convex/vendors/mutation_error_codes.test.ts: new regression test asserting every not-found/conflict path throws a ConvexError with the correct code (both client and REST handlers).

createVendor raw-error duplicates remain out of scope here (tracked by #1993).

Verification

  • bunx vitest --run --project server convex/vendors/ → 16 passed (10 new)
  • bunx tsc --noEmit → clean for changed files
  • bunx oxlint --type-aware → 0 warnings / 0 errors
  • oxfmt --check → clean

Closes #2004

@larryro

larryro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Desk Review — Issue #2004 (vendors mutations: raw Error → structured ConvexError)

Verdict: READY TO MERGE.

Reviewed via two rounds (6 parallel review agents across correctness/robustness/elegance/tests/boundaries + a dedicated RLS-propagation agent, then independent confirmation of every decisive point).

CI

All checks pass (gh pr checks): Type check, Lint, Format, Knip, Unit, UI, Browser, Build (all), Playwright (all shards), Opengrep, Migrations, Smoke test — green. No failed or pending checks; the only skipping entries are fork-PR / container jobs not applicable here.

Tests (run locally on the branch)

  • bunx vitest --run --project server convex/vendors/ → 16 passed (2 files)
  • New file alone convex/vendors/mutation_error_codes.test.ts → 10 passed
  • All 10 new error branches are covered: mutations.ts updateVendor (not-found / dup-email / dup-externalId) + deleteVendor (not-found); internal_mutations.ts updateVendor (not-found / cross-tenant / dup-email / dup-externalId) + deleteVendor (not-found / cross-tenant). Factory + query-builder mocks exercise the real handler bodies (not tautological).

What's correct

  • Every in-scope raw throw new Error(...) is converted to ConvexError({ code, message }) with the right code per branch; cross-tenant guards correctly return VENDOR_NOT_FOUND (404, avoids existence leak), conflict queries are org-scoped.
  • httpStatusForConvexCode maps VENDOR_NOT_FOUND→404, DUPLICATE_EMAIL/DUPLICATE_EXTERNAL_ID→409; withRestAuth's catch returns the 4xx for these and still logs + 500s unknown codes (no silent swallow).
  • ConvexError propagates intact through mutationWithRLS (customMutation does not try/catch the handler) and through internalMutation to withRestAuth. Both the UI path and the REST path are fixed, as the issue requires.
  • Error-code naming (SCREAMING_SNAKE) matches the codebase's dominant convention (ORG_NOT_FOUND, TASK_NOT_FOUND, DUPLICATE_NAME, LEGAL_HOLD_ACTIVE, …) and the issue's prescribed strings.

Non-blocking notes (no action required for this PR)

  1. createVendor (internal_mutations.ts:41,56) still throws raw Error — explicitly out of scope per issue Bug: Duplicate website/customer/vendor add throws a raw Error (not ConvexError) → uncaught Server Error in the client console #1993; correctly left untouched.
  2. LEGAL_HOLD_ACTIVE is not in httpStatusForConvexCode, so a legal-hold-blocked delete still yields 500. Pre-existing, legal_hold_guard.ts is not modified by this PR and is outside Bug: vendors mutations throw raw Error for not-found and conflict cases — REST API and UI get opaque 500s instead of actionable 4xx/ConvexError #2004's scope — worth a future follow-up, not a blocker here.
  3. Optional: a direct unit test for the httpStatusForConvexCode mapping (404/409) and a happy-path success assertion would round out coverage; the trivial switch is low-risk.

READY TO MERGE.

@yannickmonney
yannickmonney merged commit 00a7f1a into main Jun 29, 2026
51 checks passed
@yannickmonney
yannickmonney deleted the tale/xs7dx3z8e1mvk5yyt5f9s7basn89e7hq branch June 29, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: vendors mutations throw raw Error for not-found and conflict cases — REST API and UI get opaque 500s instead of actionable 4xx/ConvexError

2 participants