fix: add error handling for org member invite during team migration#28015
Draft
eunjae-lee wants to merge 2 commits intomainfrom
Draft
fix: add error handling for org member invite during team migration#28015eunjae-lee wants to merge 2 commits intomainfrom
eunjae-lee wants to merge 2 commits intomainfrom
Conversation
- Wrap inviteMembersWithNoInviterPermissionCheck in try-catch in moveTeam so a failed invite doesn't block team migration or other teams - Use Promise.allSettled instead of Promise.all in handleExistingUsersInvites for org invites so one member's failure doesn't block all others - Add detailed logging for member invite count, success, and per-user failures Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts">
<violation number="1" location="packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts:710">
P1: Rule violated: **Avoid Logging Sensitive Information**
Remove or redact the email from the error log payload to avoid logging PII.</violation>
</file>
<file name="packages/trpc/server/routers/viewer/organizations/createTeams.handler.ts">
<violation number="1" location="packages/trpc/server/routers/viewer/organizations/createTeams.handler.ts:260">
P1: Rule violated: **Avoid Logging Sensitive Information**
Do not log member emails in org migration logs; emails are PII and must be excluded or redacted per the logging rule.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
packages/trpc/server/routers/viewer/teams/inviteMember/utils.ts
Outdated
Show resolved
Hide resolved
packages/trpc/server/routers/viewer/organizations/createTeams.handler.ts
Outdated
Show resolved
Hide resolved
Contributor
Devin AI is addressing Cubic AI's review feedbackNew feedback has been sent to the existing Devin session. ✅ Pushed commit |
Co-Authored-By: eunjae@cal.com <hey@eunjae.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
When migrating teams to an organization, if inviting team members to the org fails (e.g. profile creation error, unique constraint violation), the entire migration could silently leave teams moved but with no org-level memberships created. This results in members appearing on the team members page but not on the org members page.
Two changes:
createTeams.handler.ts(moveTeam): WrapsinviteMembersWithNoInviterPermissionCheckin a try-catch so that a failed invite does not block the rest of the migration (redirects, subscription cancellation, subsequent team migrations). Adds logging for invite attempt details, success, and failure with full error context.inviteMember/utils.ts(handleExistingUsersInvites): ChangesPromise.all→Promise.allSettledfor the org invite path. Previously, if creating a profile/membership for any single user failed, the entire batch would reject and no users would get org memberships. Now each user is processed independently — failures are logged per-user while successful invites still proceed.Updates since last revision
userIdonly, not by email.Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
yarn db-seed) — useteampro@example.com/teampro/settings/organizations/newwith handover flowteampro@example.com, resume onboarding and select all teams to migrate/settings/organizations/<orgslug>/members— previously no members would appearNEXT_PUBLIC_LOGGER_LEVEL=3) for the new log lines:"Inviting team members to org"with member count and team/org IDs"Successfully invited team members to org"or"Failed to invite team members to org during migration"with error details"Failed to invite existing user to organization"(identified by userId) if individual invites failHuman Review Checklist
moveTeam: The catch block logs but does not re-throw. This means the org creation succeeds even if ALL member invites fail — the user sees no error, just missing members. Is this the right tradeoff vs. failing the whole migration?Promise.allSettleddownstream safety: Verify thatexistingUsersWithMembershipsNew(now filtered to only fulfilled results) is safe for seat tracking and email sending logic below it.userId(PII removed). Confirm this is sufficient for debugging — correlating userId to email requires a separate DB lookup.Link to Devin run: https://app.devin.ai/sessions/cfe7ebd1961740cea3181ccfb7e61f1e
Requested by: @eunjae-lee