Skip to content
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

[ENH] Implemented error boundary for the app #47

Merged
merged 7 commits into from
Feb 21, 2025
Merged

[ENH] Implemented error boundary for the app #47

merged 7 commits into from
Feb 21, 2025

Conversation

rmanaem
Copy link
Contributor

@rmanaem rmanaem commented Feb 19, 2025

Checklist

This section is for the PR reviewer

  • PR has an interpretable title with a prefix ([ENH], [FIX], [REF], [TST], [CI], [MNT], [INF], [MODEL], [DOC]) (see our Contributing Guidelines for more info)
  • PR has a label for the release changelog or skip-release (to be applied by maintainers only)
  • PR links to GitHub issue with mention Closes #XXXX
  • Tests pass
  • Checks pass

For new features:

  • Tests have been added

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

Summary by Sourcery

Implements an error boundary to gracefully handle unexpected errors within the application. This prevents the entire app from crashing and provides users with a fallback UI and options for reporting the issue.

New Features:

  • Implements an error boundary to catch and handle errors within the application, preventing the entire app from crashing.

Enhancements:

  • Displays a user-friendly fallback UI with a message, a link to report the issue, and a button to show error details when an error occurs.
  • Adds the ability to toggle the visibility of error details, including the error message and component stack, for debugging purposes.

Tests:

  • Adds a Cypress component test to verify that the error boundary displays the fallback UI when an error is thrown.

@rmanaem rmanaem added the pr-patch Incremental feature improvement, will increment patch version when merged (0.0.+1) label Feb 19, 2025
Copy link

sourcery-ai bot commented Feb 19, 2025

Reviewer's Guide by Sourcery

This pull request implements an error boundary to catch and handle errors that occur during the rendering of the application. It introduces a new ErrorBoundary component that wraps the App component. If an error occurs within the App component or its children, the ErrorBoundary will catch the error and display a fallback UI, preventing the entire application from crashing.

Class diagram for ErrorBoundary component

classDiagram
  class ErrorBoundary {
    - hasError: boolean
    - error: Error | null
    - errorInfo: React.ErrorInfo | null
    - showDetails: boolean
    + constructor(props: ErrorBoundaryProps)
    + static getDerivedStateFromError(): ErrorBoundaryState
    + componentDidCatch(error: Error, info: React.ErrorInfo): void
    + toggleDetails(): void
    + render(): React.ReactNode
  }
  ErrorBoundary --|> React.Component
  note for ErrorBoundary "Catches errors in the component tree and displays a fallback UI."
Loading

File-Level Changes

Change Details Files
Wrapped the App component with the ErrorBoundary component.
  • Imported the ErrorBoundary component.
  • Wrapped the App component with the ErrorBoundary component.
src/main.tsx
Implemented a new ErrorBoundary component.
  • Created a new ErrorBoundary component with state to track errors and display details.
  • Implemented getDerivedStateFromError to update the state when an error occurs.
  • Implemented componentDidCatch to log the error and error info.
  • Implemented a toggleDetails function to show/hide error details.
  • Rendered a fallback UI when an error is caught, including a message, a link to open an issue, and a button to show error details.
  • Rendered the children components if no error has occurred.
src/components/ErrorBoundary.tsx
Added a component test for the ErrorBoundary component.
  • Created a test component that throws an error when rendered.
  • Mounted the ErrorBoundary component with the error-throwing component as a child.
  • Asserted that the fallback UI is displayed when an error is thrown.
  • Asserted that the error message and component stack are displayed when the details are shown.
cypress/component/ErrorBoundary.cy.tsx

Assessment against linked issues

Issue Objective Addressed Explanation
#46 Implement an error boundary to catch and handle errors within the application.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

netlify bot commented Feb 19, 2025

Deploy Preview for staging-annotation ready!

Name Link
🔨 Latest commit ba3d8c2
🔍 Latest deploy log https://app.netlify.com/sites/staging-annotation/deploys/67b7a2179b6a920008d9f58b
😎 Deploy Preview https://deploy-preview-47--staging-annotation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 81.11%. Comparing base (34f7aee) to head (ba3d8c2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/components/ErrorBoundary.tsx 85.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
+ Coverage   80.48%   81.11%   +0.63%     
==========================================
  Files          17       18       +1     
  Lines         123      143      +20     
  Branches       17       23       +6     
==========================================
+ Hits           99      116      +17     
- Misses         24       27       +3     
Flag Coverage Δ
tests 81.11% <85.00%> (+0.63%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rmanaem rmanaem marked this pull request as ready for review February 19, 2025 20:49
Copy link

@surchs surchs left a comment

Choose a reason for hiding this comment

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

Thanks @rmanaem, this looks good. But left two clarity comments for you to look into

With that

🧑‍🍳

@rmanaem rmanaem merged commit b1c2a58 into main Feb 21, 2025
14 checks passed
@surchs surchs deleted the enh-46 branch February 21, 2025 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-patch Incremental feature improvement, will increment patch version when merged (0.0.+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement error boundary
2 participants