Repository navigation
fix(convex): throw ConvexError codes from org/user lifecycle mutations (#2018) - #2213
Conversation
#2018) delete_cleanup.ts, create_member.ts and create_user_without_session.ts threw raw Error, surfacing every rejection as an opaque "Server Error". They now throw ConvexError with stable codes (UNAUTHENTICATED, FORBIDDEN, DEFAULT_ORG_PROTECTED, DUPLICATE_MEMBER, DUPLICATE_EMAIL, USER_CREATION_FAILED). The add-member dialog now shows DUPLICATE_MEMBER inline on the email field (emailAlreadyMember in en/de/fr). Adds unit tests for the org-deletion codes and a dialog regression test. Closes #2018
Desk review — #2018 (ConvexError codes for org/user lifecycle mutations)CI: all required checks green (Type check, Unit, UI, Lint, Format, Build platform/convex, Playwright ×16, Smoke — What's solid
Blocking1. No backend test for Non-blocking notes (not required for merge)
Verdict: NOT READY — CHANGES REQUIRED (add backend test coverage for |
Adds convex/users/create_member.test.ts asserting the converted lifecycle rejections throw ConvexError with stable codes (UNAUTHENTICATED, FORBIDDEN, DUPLICATE_MEMBER, PASSWORD_REQUIRED, USER_CREATION_FAILED), per desk-review feedback on #2213. Follows the rejects.toMatchObject({ data: { code } }) pattern from update_user_password.test.ts and delete_cleanup.test.ts.
larryro
left a comment
There was a problem hiding this comment.
Desk Review — #2018 (ConvexError codes for org/user lifecycle mutations)
Verdict: READY TO MERGE.
Verification performed
- Checked out branch
tale/xs7epgw2w66hzc48c08qe44kp589fn6g, installed deps withbun install. - Ran the project's own tests:
bunx vitest --run --project server convex/organizations/delete_cleanup.test.ts convex/users/create_member.test.ts→ 2 files, 13 tests passed.bunx vitest --run --project client member-add-dialog→ 1 file, 4 tests passed.
- CI on this PR: all 45 checks green (
gh pr checks), including Type check, Lint, Format, Knip, Unit, Browser, UI, and 16 Playwright shards. (Theskippingentries are fork-PR-only jobs, not failures.)
What's correct
- All eight in-scope raw
throw new Error(...)sites from the issue are nowConvexError({ code, message })with sensible, stable codes —grep "throw new Error"returns zero matches across the three files. Codes:UNAUTHENTICATED,FORBIDDEN,DEFAULT_ORG_PROTECTED,DUPLICATE_MEMBER,USER_CREATION_FAILED,DUPLICATE_EMAIL. - Control flow / check ordering unchanged (auth → role → slug/membership); success return values unchanged. The
DUPLICATE_MEMBERcheck is correctly gated behind the admin authorization check, so it can't be used for unauthenticated user-enumeration. DUPLICATE_MEMBERis wired to an inline email-field error inmember-add-dialog.tsx, mirroring the existingPASSWORD_REQUIRED(#1470) pattern exactly. New i18n keyauth.validation.emailAlreadyMemberis present and genuinely translated in en/de/fr.- New tests assert
error.data.codefor every reachable branch and that rejections areinstanceof ConvexError(regression guard against raw Error).
Non-blocking observations (not required for merge)
app/features/organization/hooks/use-delete-organization.ts(~line 86): the catch showserr.messagein the toast description. For aConvexError,.messageis the JSON-serialized payload ({"code":"FORBIDDEN","message":"..."}), not a clean string. Pre-fix this flow already surfaced a masked "Server Error", so this is not a regression in capability, but consider readingerr.data?.message/err.data?.codefor a cleaner toast. The issue only required inline display for the two validation codes, which is done.convex/users/create_user_without_session.tsis a plain helper with no in-repo caller (not wrapped inmutation()), so its newDUPLICATE_EMAILcode has no UI to wire to and its three error branches are untested. This is pre-existing orphaned code; converting its errors is exactly what the issue asked, so it's acceptable scope — flagging only for awareness.- The dialog test asserts the error via
findByTextrather than binding to the email field specifically — passes and is adequate, just slightly less strict than ideal.
None of the above block the merge. The change is focused, follows repo conventions, fixes the reported issue, and is fully covered by passing tests and green CI.
READY TO MERGE.
Summary
Resolves #2018.
organizations/delete_cleanup.ts,users/create_member.tsandusers/create_user_without_session.tsthrew rawError, so every rejection surfaced as an opaque "Server Error". They now throwConvexError({ code })with stable codes the UI can branch on.Codes introduced
UNAUTHENTICATEDFORBIDDENDEFAULT_ORG_PROTECTEDUNAUTHENTICATEDFORBIDDENDUPLICATE_MEMBERUSER_CREATION_FAILEDDUPLICATE_EMAILFrontend
The add-member dialog now surfaces
DUPLICATE_MEMBERas an inline error on the email field (newauth.validation.emailAlreadyMemberkey in en/de/fr), matching the existingPASSWORD_REQUIREDinline pattern — these are validation errors users should fix in-form, per the issue notes.Tests
convex/organizations/delete_cleanup.test.ts— new: asserts each rejection throwsConvexErrorwith the expected code + the success path.member-add-dialog.test.tsx— added aDUPLICATE_MEMBERregression test.Closes #2018