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

fix: error boundary #5003

Merged
merged 1 commit into from
May 27, 2024
Merged

fix: error boundary #5003

merged 1 commit into from
May 27, 2024

Conversation

alter-eggo
Copy link
Contributor

@alter-eggo alter-eggo commented Feb 28, 2024

Try out Leather build 91c981bExtension build, Test report, Storybook, Chromatic

I seems current app's error boundary doesn't work. I decided not to try fix that legacy code, and just added new component for this. I believe it's ok for now, still way better than default error screen:

Screenshot 2024-02-28 at 23 45 58

Summary by CodeRabbit

  • New Features

    • Introduced a new RouterErrorBoundary for enhanced error handling in routes.
    • Revamped error display UI with new components and functionalities like error copying and reloading.
  • Improvements

    • Updated error handling in the app to provide more detailed messages and enhanced user options.
    • Modified CodeBlock component in contract deploy details to include a new color prop.
  • Removals

    • Removed AppErrorBoundary from the rendering hierarchy.
    • Eliminated unused useErrorStackTraceState function and errorStackTraceState constant to simplify state management.
  • Style

    • Updated color property in the theme constant from '#fff' to 'unset'.

These changes aim to improve error handling, enhance the user interface, and streamline the codebase.

@alter-eggo
Copy link
Contributor Author

added stack trace
Screenshot 2024-02-29 at 01 16 45

Copy link
Contributor

@fbwoolf fbwoolf left a comment

Choose a reason for hiding this comment

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

@pete-watters just checking if you touched this at all with your work? Is there an open issue to revisit this? I'll check.

@fbwoolf
Copy link
Contributor

fbwoolf commented Feb 28, 2024

There is this issue, outdated and can be closed here? #2921

@pete-watters
Copy link
Contributor

Thanks for fixing this @alter-eggo . Can you please check if we have an issue before doing stuff like this? We shouldn't have PRs with no issue.

There is a task for this, with a design in the Establish UI Library project so I assigned it to you now. Please check that this implementation matches the design.

const body = 'An error occurred in the app.';
const errorPayload = error.message;

return (
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please refactor this so it's a dumb component, receiving some props it needs and located in the ui/components folder?

We should also add a storybook story for it so we can see how it looks

Copy link
Contributor

@pete-watters pete-watters left a comment

Choose a reason for hiding this comment

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

Please check #3986 to make sure we solve this fully

Copy link
Contributor

@pete-watters pete-watters left a comment

Choose a reason for hiding this comment

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

I'm changing this from Request changes as we checked with design and it's pending their response.

Copy link

coderabbitai bot commented May 27, 2024

Warning

Rate Limit Exceeded

@alter-eggo has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 49 minutes and 49 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between d48f4c8 and 91c981b.

Walkthrough

The recent changes involve significant updates to error handling, UI components, and state management within the application. Key modifications include the removal of the AppErrorBoundary, the introduction of a RouterErrorBoundary, updates to the PrismType interface, and adjustments to the CodeBlock component's color properties. Additionally, unused error stack trace state management functions and constants were removed to simplify the codebase.

Changes

Files/Modules Change Summary
src/app/app.tsx Removed AppErrorBoundary from ConnectedApp function, directly rendering AppRoutes.
src/app/common/clarity-prism.ts Added export keyword to PrismType interface.
src/app/features/errors/app-error-boundary.tsx Introduced RouterErrorBoundary with new error handling UI components and functionality.
src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx Added color prop with value #fff to CodeBlock component in ContractCodeSection function.
src/app/routes/app-routes.tsx Added RouterErrorBoundary import, restructured routes within useAppRoutes function, and adjusted various route paths and elements.
src/app/store/ui/ui.hooks.ts Removed useErrorStackTraceState function and errorStackTraceState import, simplifying the file.
src/app/store/ui/ui.ts Removed errorStackTraceState constant, affecting UI state management.
src/app/ui/components/highlighter.tsx Replaced PrismLib interface with PrismType imported from @app/common/clarity-prism.
src/app/ui/utils/prism.tsx Changed color property in plain object of theme constant from '#fff' to 'unset'.

In code’s embrace, we find our way,
With changes bright as the dawn of day.
Errors caught, and routes refined,
A clearer path for all to find.
Colors shift from white to none,
Our journey through the code is done.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 1

Outside diff range and nitpick comments (3)
src/app/app.tsx (1)

Line range hint 39-39: Avoid using any for type definitions to ensure type safety and better developer experience.

- localConfig: localConfig as any,
+ localConfig: localConfig as LocalConfigType, // Define or import `LocalConfigType` appropriately
src/app/ui/utils/prism.tsx (1)

Line range hint 16-16: Replace any with specific types in props definitions to enhance type safety and maintainability.

- [otherProp: string]: any;
+ [otherProp: string]: SpecificType; // Replace `SpecificType` with the actual expected type

Also applies to: 24-24, 32-32, 39-39

src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx (1)

Line range hint 38-38: Replace any with a specific type for the prism prop to ensure type safety and better integration with TypeScript.

- prism={Prism as any}
+ prism={Prism as PrismType} // Define or import `PrismType` appropriately
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a24c6de and f7a5a0e.
Files selected for processing (7)
  • src/app/app.tsx (2 hunks)
  • src/app/features/errors/app-error-boundary.tsx (1 hunks)
  • src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx (1 hunks)
  • src/app/routes/app-routes.tsx (2 hunks)
  • src/app/store/ui/ui.hooks.ts (1 hunks)
  • src/app/store/ui/ui.ts (1 hunks)
  • src/app/ui/utils/prism.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/app/store/ui/ui.hooks.ts
Additional Context Used
Biome (10)
src/app/app.tsx (1)

39-39: Unexpected any. Specify a different type.

src/app/features/errors/app-error-boundary.tsx (1)

77-77: Unexpected any. Specify a different type.

src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx (2)

38-38: Unexpected any. Specify a different type.


2-3: Some named imports are only used as types.

src/app/ui/utils/prism.tsx (6)

16-16: Unexpected any. Specify a different type.


24-24: Unexpected any. Specify a different type.


32-32: Unexpected any. Specify a different type.


39-39: Unexpected any. Specify a different type.


1-1: All these imports are only used as types.


2-3: All these imports are only used as types.

Additional comments not posted (6)
src/app/store/ui/ui.ts (1)

Line range hint 1-9: The existing implementation of loadingState using atomFamily appears to be correct and well-implemented.

src/app/app.tsx (1)

44-44: Simplified rendering logic in ConnectedApp by directly rendering AppRoutes and conditionally Devtools enhances clarity and performance.

src/app/ui/utils/prism.tsx (1)

92-92: Setting the default text color to 'unset' in the theme configuration allows for more flexible theming. Ensure this change aligns with the overall design and theming strategy.

src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx (1)

34-34: Adding a color prop to CodeBlock enhances visual clarity. Ensure the chosen color (#fff) aligns with the design guidelines.

src/app/features/errors/app-error-boundary.tsx (1)

16-101: The implementation of RouterErrorBoundary is robust, providing detailed error information and user-friendly interaction options. Ensure all new hooks and components are thoroughly tested.

src/app/routes/app-routes.tsx (1)

84-263: Integration of RouterErrorBoundary in the routing configuration enhances error handling capabilities. Ensure thorough testing, especially in scenarios where routing errors are expected to occur.

my="space.05"
mx="space.05"
p="space.04"
prism={Prism as any}
Copy link

Choose a reason for hiding this comment

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

Replace any with a specific type for the prism prop to ensure type safety and better integration with TypeScript.

- prism={Prism as any}
+ prism={Prism as PrismType} // Define or import `PrismType` appropriately

Committable suggestion was skipped due low confidence.

Copy link
Contributor

@edgarkhanzadian edgarkhanzadian left a comment

Choose a reason for hiding this comment

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

Great work! Left some optional comments here and there

src/app/features/errors/app-error-boundary.tsx Outdated Show resolved Hide resolved
src/app/features/errors/app-error-boundary.tsx Outdated Show resolved Hide resolved
Comment on lines 17 to 18
const error = useRouteError() as Error;
const errorObj = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks sketchy. Let's do some runtime checking.

Something like?
if (!isError) return children; or nav home?

And why the stringify/parse? I have no idea why this is happening, and nor might the next person reading this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, I added this a while ago, not recall now why. removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if there could be !isError as it's error boundary. but even if it could -> better to show at least "Unknown error" msg.
if we nav home and error happened on home screen - there will be just blank screen

src/app/features/errors/app-error-boundary.tsx Outdated Show resolved Hide resolved
src/app/features/errors/app-error-boundary.tsx Outdated Show resolved Hide resolved
Copy link

@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: 1

Outside diff range and nitpick comments (2)
src/app/app.tsx (1)

Line range hint 39-39: Replace any with a more specific type to enhance type safety.

- localConfig: localConfig as any,
+ localConfig: localConfig as LocalConfigType, // Assuming LocalConfigType is defined appropriately
src/app/common/clarity-prism.ts (1)

Line range hint 55-61: Replace string concatenation with template literals in regex patterns to improve readability and maintainability.

- pattern: RegExp(par + '(?:or|and|xor|not|begin|let|if|ok|err|unwrap\\!|unwrap-err\\!|unwrap-panic|unwrap-err-panic|match|try\\!|asserts\\!|map-get\\?|var-get|contract-map-get\\?|get|tuple|define-public|define-private|define-constant|define-map|define-data-var|define-fungible-token|define-non-fungible-token|define-read-only)' + space),
+ pattern: RegExp(`${par}(?:or|and|xor|not|begin|let|if|ok|err|unwrap\\!|unwrap-err\\!|unwrap-panic|unwrap-err-panic|match|try\\!|asserts\\!|map-get\\?|var-get|contract-map-get\\?|get|tuple|define-public|define-private|define-constant|define-map|define-data-var|define-fungible-token|define-non-fungible-token|define-read-only)${space}`),

Also applies to: 66-66, 71-75, 81-84, 90-92, 97-97

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f7a5a0e and d48f4c8.
Files selected for processing (9)
  • src/app/app.tsx (2 hunks)
  • src/app/common/clarity-prism.ts (1 hunks)
  • src/app/features/errors/app-error-boundary.tsx (1 hunks)
  • src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx (1 hunks)
  • src/app/routes/app-routes.tsx (2 hunks)
  • src/app/store/ui/ui.hooks.ts (1 hunks)
  • src/app/store/ui/ui.ts (1 hunks)
  • src/app/ui/components/highlighter.tsx (2 hunks)
  • src/app/ui/utils/prism.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/app/routes/app-routes.tsx
  • src/app/store/ui/ui.hooks.ts
  • src/app/store/ui/ui.ts
Additional Context Used
Biome (20)
src/app/app.tsx (1)

39-39: Unexpected any. Specify a different type.

src/app/common/clarity-prism.ts (7)

7-7: Unexpected any. Specify a different type.


55-61: Template literals are preferred over string concatenation.


66-66: Template literals are preferred over string concatenation.


71-75: Template literals are preferred over string concatenation.


81-84: Template literals are preferred over string concatenation.


90-92: Template literals are preferred over string concatenation.


97-97: Template literals are preferred over string concatenation.

src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx (2)

38-38: Unexpected any. Specify a different type.


2-3: Some named imports are only used as types.

src/app/ui/components/highlighter.tsx (4)

143-143: Unexpected any. Specify a different type.


7-14: Some named imports are only used as types.


35-35: Avoid using the index of an array as key property in an element.


118-118: Avoid using the index of an array as key property in an element.

src/app/ui/utils/prism.tsx (6)

16-16: Unexpected any. Specify a different type.


24-24: Unexpected any. Specify a different type.


32-32: Unexpected any. Specify a different type.


39-39: Unexpected any. Specify a different type.


1-1: All these imports are only used as types.


2-3: All these imports are only used as types.

Additional comments not posted (6)
src/app/app.tsx (1)

44-44: Simplified rendering hierarchy by directly using AppRoutes enhances clarity and maintainability.

src/app/ui/utils/prism.tsx (1)

92-92: Using 'unset' for the color property enhances theming flexibility by allowing inheritance from parent elements.

src/app/common/clarity-prism.ts (1)

3-3: Exporting the PrismType interface promotes reusability and modular design.

src/app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details.tsx (1)

34-34: Adding a color prop with the value #fff to the CodeBlock component ensures text visibility against varying backgrounds.

src/app/features/errors/app-error-boundary.tsx (1)

51-120: The RouterErrorBoundary component enhances error handling with user-friendly messages and functionality for copying the error. Good implementation of user interaction features.

src/app/ui/components/highlighter.tsx (1)

137-137: Explicitly typing the prism prop as PrismType enhances type safety and clarity in the Highlighter component.

src/app/features/errors/app-error-boundary.tsx Outdated Show resolved Hide resolved
@alter-eggo alter-eggo added this pull request to the merge queue May 27, 2024
Merged via the queue into dev with commit 4fd1dbe May 27, 2024
30 checks passed
@alter-eggo alter-eggo deleted the fix/error-boundary branch May 27, 2024 15:18
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.

Add global app error screen Fix error boundary to correctly handle and log errors
5 participants