Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Nov 29, 2025

#575

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Send Error Email test button in Admin Panel settings.
  • Improvements

    • Enhanced error email reporting to include username information.
    • Improved error email template with better field organization.
    • Enhanced error handling with fallback values for missing system data.

✏️ Tip: You can customize this high-level summary in your review settings.

…error context, add username to error email payload, and enhance EmailTemplate to display username. Update ErrorEmailProps type to require username. (#575)
@linear
Copy link

linear bot commented Nov 29, 2025

@supabase
Copy link

supabase bot commented Nov 29, 2025

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@mdroidian
Copy link
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 29, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 29, 2025

📝 Walkthrough

Walkthrough

The PR refactors the error reporting system by centralizing user identification in the sendErrorEmail utility, removes user context data from direct error handlers, adds a test error email button to the admin panel, updates the email template to display the username field, and makes version/buildDate required fields while adding username to ErrorEmailProps.

Changes

Cohort / File(s) Summary
Error context cleanup
apps/roam/src/components/canvas/Tldraw.tsx, apps/roam/src/components/canvas/useRoamStore.ts
Removed the user field from context objects passed to sendErrorEmail in error handlers
sendErrorEmail utility enhancement
apps/roam/src/utils/sendErrorEmail.ts
Added retrieval of current user display name via getCurrentUserDisplayName, includes username in payload with "unknown" fallback, adds default fallbacks for version and buildDate, and improves error message handling in catch block
Admin panel test feature
apps/roam/src/components/settings/AdminPanel.tsx
Added sendErrorEmail import and new "Send Error Email" button in FeatureFlagsTab to trigger test error emails
Email template and API refactoring
apps/website/app/api/errors/EmailTemplate.tsx, apps/website/app/api/errors/route.tsx
Introduced ErrorField component for consistent field rendering, added username prop and display to EmailTemplate, converted POST and OPTIONS route handlers from function declarations to arrow functions, added createCorsResponse helper for centralized response creation
Type definitions update
packages/types/index.ts
Made version and buildDate required fields in ErrorEmailProps, added new required username: string field

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify that removing the user field from error handlers does not break downstream error tracking or logging
  • Confirm getCurrentUserDisplayName properly fetches and handles null/undefined cases before fallback to "unknown"
  • Test the AdminPanel button functionality and error handling when the email send fails
  • Review arrow function conversion in route handlers for any behavioral changes (especially context binding)
  • Validate that all callers of sendErrorEmail align with the updated required fields in ErrorEmailProps

Possibly related PRs

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding username to error handling, refactoring error email flow, and fixing CORS. It's specific, concise, and covers the primary objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
apps/roam/src/components/settings/AdminPanel.tsx (1)

31-31: Send Error Email test button looks good; consider tightening error handling and Checkbox state

The admin-only test button wiring is straightforward and correctly calls sendErrorEmail with a synthetic error. Two small cleanups you might consider:

  • For the Checkbox, you're tracking useReifiedRelations in state but also using defaultChecked. Either drop the state (uncontrolled, use defaultChecked={getSetting(...)} directly) or make it controlled with checked={useReifiedRelations} to avoid the hybrid pattern.
  • For the test button, .catch(() => {}) silently swallows failures. Even a simple console.error (or reusing whatever logging you prefer) would help debugging if the endpoint or CORS misbehaves, while keeping UX lightweight for this admin/testing control.

Also applies to: 330-363

packages/types/index.ts (1)

7-9: ErrorEmailProps stricter contract – ensure all callers now populate the new required fields

Making version, buildDate, and username required is consistent with the new email template and Roam sender logic, but the API handler currently does a blind cast from request.json() to ErrorEmailProps. Older clients (or other apps like Obsidian) that haven’t been updated could still POST payloads missing these fields, leading to undefined at runtime despite the static type.

I’d suggest either:

  • Verifying all existing producers of ErrorEmailProps now always include version, buildDate, and username, or
  • Adding lightweight runtime validation/defaulting in the API route before calling EmailTemplate so the handler is robust against partial payloads.
apps/website/app/api/errors/route.tsx (1)

10-25: CORS helper + handlers are solid; consider explicit return types and revisiting the eslint-disable

The refactor to createCorsResponse and consistent CORS handling for POST/OPTIONS looks good and should make local Roam dev friendlier. A few focused improvements:

  • Add explicit return types to match the TS guidelines, e.g.:

    export const POST = async (request: Request): Promise<Response> => {  };
    export const OPTIONS = (request: Request): Response => {  };
  • OPTIONS currently re-implements the same CORS header logic as createCorsResponse. You could optionally delegate to createCorsResponse(null, 204, origin) to keep behavior centralized (and reduce chances of future drift).

  • The // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment on username suggests the linter considers the request body unsafe. A more robust pattern is to treat await request.json() as unknown and validate/narrow to ErrorEmailProps (e.g. via a small type guard or schema) before destructuring and passing into EmailTemplate, which should remove the need for the suppression and improve safety for untrusted input.

Also applies to: 27-82, 86-102

apps/roam/src/utils/sendErrorEmail.ts (1)

4-4: sendErrorEmail payload updates look good; add explicit return type and minor typing polish

The added username and the version/buildDate fallbacks align well with the updated ErrorEmailProps, and the improved catch block makes failures much easier to debug.

Two small TS/guideline tweaks you might consider:

  • Give sendErrorEmail an explicit return type to match the repo rules:

    const sendErrorEmail = async (): Promise<void> => {  };
  • Since ErrorEmailProps is only used for typing, you can import it as a type to avoid any chance of runtime import overhead:

    import type { ErrorEmailProps } from "@repo/types";

Also applies to: 6-52

apps/website/app/api/errors/EmailTemplate.tsx (1)

4-9: EmailTemplate refactor improves clarity; consider more flexible props and explicit return types

The ErrorField extraction and the new Username field make the template much cleaner and align with the updated ErrorEmailProps.

Two minor refinements:

  • If you ever want these fields to render richer content (e.g. fallbacks, code formatting), you could widen ErrorField to accept React.ReactNode instead of just string:

    const ErrorField = ({ label, value }: { label: string; value: React.ReactNode }) => ();
  • To match the TS guidelines, you may want to add explicit return types to ErrorField and EmailTemplate, e.g. (): JSX.Element.

Using inline styles here is reasonable given this is email HTML and not styled by Tailwind at runtime.

Also applies to: 19-30

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcf2302 and 526f8e3.

📒 Files selected for processing (7)
  • apps/roam/src/components/canvas/Tldraw.tsx (0 hunks)
  • apps/roam/src/components/canvas/useRoamStore.ts (0 hunks)
  • apps/roam/src/components/settings/AdminPanel.tsx (2 hunks)
  • apps/roam/src/utils/sendErrorEmail.ts (3 hunks)
  • apps/website/app/api/errors/EmailTemplate.tsx (2 hunks)
  • apps/website/app/api/errors/route.tsx (3 hunks)
  • packages/types/index.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • apps/roam/src/components/canvas/useRoamStore.ts
  • apps/roam/src/components/canvas/Tldraw.tsx
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/main.mdc)

**/*.{ts,tsx}: Use Tailwind CSS for styling where possible
When refactoring inline styles, use tailwind classes
Prefer type over interface in TypeScript
Use explicit return types for functions
Avoid any types when possible
Prefer arrow functions over regular function declarations
Use named parameters (object destructuring) when a function has more than 2 parameters
Use PascalCase for components and types
Use camelCase for variables and functions
Use UPPERCASE for constants
Function names should describe their purpose clearly
Prefer early returns over nested conditionals for better readability

Files:

  • packages/types/index.ts
  • apps/roam/src/components/settings/AdminPanel.tsx
  • apps/website/app/api/errors/route.tsx
  • apps/roam/src/utils/sendErrorEmail.ts
  • apps/website/app/api/errors/EmailTemplate.tsx
apps/roam/**/*.{js,ts,tsx,jsx,json}

📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)

Prefer existing dependencies from package.json when working on the Roam Research extension

Files:

  • apps/roam/src/components/settings/AdminPanel.tsx
  • apps/roam/src/utils/sendErrorEmail.ts
apps/roam/**/*.{ts,tsx,jsx,js,css,scss}

📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)

Use BlueprintJS 3 components and Tailwind CSS for platform-native UI in the Roam Research extension

Files:

  • apps/roam/src/components/settings/AdminPanel.tsx
  • apps/roam/src/utils/sendErrorEmail.ts
apps/roam/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)

apps/roam/**/*.{ts,tsx,js,jsx}: Use the roamAlphaApi docs from https://roamresearch.com/#/app/developer-documentation/page/tIaOPdXCj when implementing Roam functionality
Use Roam Depot/Extension API docs from https://roamresearch.com/#/app/developer-documentation/page/y31lhjIqU when implementing extension functionality

Files:

  • apps/roam/src/components/settings/AdminPanel.tsx
  • apps/roam/src/utils/sendErrorEmail.ts
apps/roam/**

📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)

Implement the Discourse Graph protocol in the Roam Research extension

Files:

  • apps/roam/src/components/settings/AdminPanel.tsx
  • apps/roam/src/utils/sendErrorEmail.ts
apps/website/**

📄 CodeRabbit inference engine (.cursor/rules/website.mdc)

Prefer existing dependencies from apps/website/package.json when adding dependencies to the website application

Files:

  • apps/website/app/api/errors/route.tsx
  • apps/website/app/api/errors/EmailTemplate.tsx
🧠 Learnings (2)
📚 Learning: 2025-06-19T19:43:43.380Z
Learnt from: sid597
Repo: DiscourseGraphs/discourse-graph PR: 226
File: apps/roam/src/components/settings/HomePersonalSettings.tsx:123-149
Timestamp: 2025-06-19T19:43:43.380Z
Learning: The "Fetch Embeddings for nodes" button in HomePersonalSettings.tsx is for testing purposes only, so it doesn't require production-level error handling or user feedback improvements.

Applied to files:

  • apps/roam/src/components/settings/AdminPanel.tsx
📚 Learning: 2025-11-25T00:52:27.779Z
Learnt from: CR
Repo: DiscourseGraphs/discourse-graph PR: 0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-11-25T00:52:27.779Z
Learning: Applies to **/*.{ts,tsx} : Prefer arrow functions over regular function declarations

Applied to files:

  • apps/website/app/api/errors/route.tsx
🧬 Code graph analysis (4)
apps/roam/src/components/settings/AdminPanel.tsx (1)
apps/roam/src/utils/extensionSettings.ts (1)
  • setSetting (13-16)
apps/website/app/api/errors/route.tsx (1)
packages/types/index.ts (1)
  • ErrorEmailProps (1-11)
apps/roam/src/utils/sendErrorEmail.ts (1)
packages/types/index.ts (1)
  • ErrorEmailProps (1-11)
apps/website/app/api/errors/EmailTemplate.tsx (1)
packages/types/index.ts (1)
  • ErrorEmailProps (1-11)

@mdroidian mdroidian merged commit 9b64e0a into main Nov 29, 2025
5 checks passed
@mdroidian mdroidian deleted the eng-1090-further-enhance-error-email branch November 29, 2025 20:04
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.

2 participants