-
-
Notifications
You must be signed in to change notification settings - Fork 193
fix: surface invite-email send failures instead of swallowing them #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SomSamantray
wants to merge
14
commits into
oss-apps:main
Choose a base branch
from
SomSamantray:fix/722-surface-smtp-invite-email-errors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
13540ff
fix: propagate sendInviteEmail's send result instead of discarding it
SomSamantray 1203c10
fix: surface invite-email send failures from inviteFriend mutation
SomSamantray 5959eb8
fix: show toast and reconcile UI state on invite-email failure
SomSamantray ddf6890
fix(review): apply review findings
SomSamantray 501dc85
chore: fix comment wording mangled by pre-commit autofix
SomSamantray f8bef61
fix: add machine-readable AppError cause for tRPC error discrimination
SomSamantray d60a7c7
fix: escape inviter name in invite-email HTML to prevent HTML injection
SomSamantray 121c948
fix: rate-limit invite-email sends and stop logging raw recipient emails
SomSamantray 70e58a6
fix: discriminate genuine send failures from other invite errors, cli…
SomSamantray 31fa028
refactor: consolidate invite-error codes and toast mapping into one m…
SomSamantray b0cadd3
fix: harden inviteFriend against concurrent-create races and silent t…
SomSamantray 135eb75
test: add coverage for inviteErrors.ts; align to project's test-struc…
SomSamantray 13e6ee4
fix: apply the same error-recovery pattern to SelectUserOrGroup.tsx
SomSamantray 1c9bd68
fix: wire the send_invite button to actually send an invite email
SomSamantray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20260906080000_add_user_last_invited_at/migration.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "User" ADD COLUMN "lastInvitedAt" TIMESTAMP(3); |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { InviteErrorCode, getInviteErrorToastKey, isInviteErrorCode } from '~/lib/inviteErrors'; | ||
|
|
||
| describe('isInviteErrorCode', () => { | ||
| describe('when given a known InviteErrorCode value', () => { | ||
| it.each(Object.values(InviteErrorCode))('returns true for %s', (code) => { | ||
| expect(isInviteErrorCode(code)).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when given anything else', () => { | ||
| it.each([undefined, null, 123, {}, 'SOME_UNRELATED_CODE', ''])( | ||
| 'returns false for %p', | ||
| (value) => { | ||
| expect(isInviteErrorCode(value)).toBe(false); | ||
| }, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getInviteErrorToastKey', () => { | ||
| describe('when the code is INVITE_EMAIL_SEND_FAILED', () => { | ||
| it('returns the invite-email-failed key', () => { | ||
| expect(getInviteErrorToastKey(InviteErrorCode.INVITE_EMAIL_SEND_FAILED)).toBe( | ||
| 'errors.invite_email_failed', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the code is any other InviteErrorCode value', () => { | ||
| it.each([InviteErrorCode.INVITES_DISABLED, InviteErrorCode.INVITE_RATE_LIMITED])( | ||
| 'returns the generic add-member-failed key for %s', | ||
| (code) => { | ||
| expect(getInviteErrorToastKey(code)).toBe('errors.add_member_failed'); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| describe('when the code is unknown, null, or undefined', () => { | ||
| it.each(['SOME_UNRELATED_CODE', null, undefined])( | ||
| 'returns the generic add-member-failed key for %p', | ||
| (value) => { | ||
| expect(getInviteErrorToastKey(value)).toBe('errors.add_member_failed'); | ||
| }, | ||
| ); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| export const InviteErrorCode = { | ||
| INVITES_DISABLED: 'INVITES_DISABLED', | ||
| INVITE_RATE_LIMITED: 'INVITE_RATE_LIMITED', | ||
| INVITE_EMAIL_SEND_FAILED: 'INVITE_EMAIL_SEND_FAILED', | ||
| } as const; | ||
|
|
||
| const inviteErrorCodes: string[] = Object.values(InviteErrorCode); | ||
|
|
||
| export const isInviteErrorCode = (appErrorCode: unknown): boolean => | ||
| 'string' === typeof appErrorCode && inviteErrorCodes.includes(appErrorCode); | ||
|
|
||
| export const getInviteErrorToastKey = ( | ||
| appErrorCode: string | null | undefined, | ||
| ): 'errors.invite_email_failed' | 'errors.add_member_failed' => | ||
| InviteErrorCode.INVITE_EMAIL_SEND_FAILED === appErrorCode | ||
| ? 'errors.invite_email_failed' | ||
| : 'errors.add_member_failed'; |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| import { AppError, getAppErrorCode } from '~/server/api/appError'; | ||
|
|
||
| describe('getAppErrorCode', () => { | ||
| describe('when the cause is an AppError', () => { | ||
| it('returns its code', () => { | ||
| expect(getAppErrorCode(new AppError('SOME_CODE', 'failed'))).toBe('SOME_CODE'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the cause is not an AppError', () => { | ||
| it('returns null for undefined', () => { | ||
| expect(getAppErrorCode(undefined)).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null for a plain Error', () => { | ||
| expect(getAppErrorCode(new Error('boom'))).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null for a ZodError', () => { | ||
| const result = z.string().safeParse(123); | ||
| expect(result.success).toBe(false); | ||
| expect(getAppErrorCode(!result.success ? result.error : undefined)).toBeNull(); | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| export class AppError extends Error { | ||
| readonly code: string; | ||
|
|
||
| constructor(code: string, message: string) { | ||
| super(message); | ||
| this.name = 'AppError'; | ||
| this.code = code; | ||
| } | ||
| } | ||
|
|
||
| export const getAppErrorCode = (cause: unknown): string | null => | ||
| cause instanceof AppError ? cause.code : null; |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.