-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
feat: error boundary in layout to handle application errors / crashes #1108
base: master
Are you sure you want to change the base?
feat: error boundary in layout to handle application errors / crashes #1108
Conversation
In Firefox:In Chrome:The Error Boundary is detecting the error being generated by the browser on too much recursion and rendering the Error component. Used this asyncapi document for testing asyncapi: 3.0.0
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
channels:
userSignedup:
address: user/signedup
messages:
UserSignedUp:
$ref: '#/components/messages/UserSignedUp'
x-recursion: #RECURSION here
$ref: '#'
operations:
sendUserSignedup:
action: send
channel:
$ref: '#/channels/userSignedup'
messages:
- $ref: '#/channels/userSignedup/messages/UserSignedUp'
x-recursion: #RECURSION here
$ref: '#'
components:
messages:
UserSignedUp:
x-recursion: #RECURSION here
$ref: '#'
payload:
type: object
properties:
x-recursion: #RECURSION here
$ref: '#'
displayName:
type: string
description: Name of the user
email:
type: string |
@reachaadrika could you please review this pull request too when you get a chance? 😄 Thanks in advance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome improvement, but i noticed when i fix the recursive properties in the schema, the error still persists in the UI until i either refresh or re-paste a valid schema 🤔
{configShow.sidebar && <Sidebar />} | ||
<div className="panel--center relative py-8 flex-1"> | ||
<div className="relative z-10"> | ||
{configShow.errors && error && <Error error={error} />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line still relevant? i mean since you've imported the error boundary in the layout container and it already includes the error component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is important.
This line handles the errors in our document when parsing it. The errors are in turn diagnostics with severity 0. Introduced in this PR: https://github.com/asyncapi/asyncapi-react/pull/1082/files
The error boundary, on the other hand, is used to catch unexpected application errors, such as a recursion error, and is a separate concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line handles the errors in our document when parsing it. The errors are in turn diagnostics with severity 0.
Aren't we already handling these errors here
concatenatedConfig.show?.errors && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error boundary, on the other hand, is used to catch unexpected application errors, such as a recursion error, and is a separate concern.
I agree with you 👍🏾
my question now is if {configShow.errors && error && <Error error={error} />}
is relevant if we are already handling it in the standalone code, don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice observation 👀
As far as i can tell, here in Standalone. Whenever there is an error in the document. Our asyncapi
variable becomes undefined. So the if else statements here in standalone catch the error.
And it never reaches our Error component in Layout.
So maybe we can remove the Error component rendering in Layout. Correct me if i am wrong or missing out on something.
Or we can move the conditional statements into Layout to check in one place only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with some modification of prop types
we can put this in Layout.tsx and remove the Error rendering from Standalone
return (
<ConfigContext.Provider value={config}>
<section className="aui-root">
{asyncapi ? (
<SpecificationContext.Provider value={asyncapi}>
<div
className={`${observerClassName} relative md:flex bg-white leading-normal`}
id={config.schemaID ?? undefined}
ref={ref}
>
{configShow.sidebar && <Sidebar />}
<div className="panel--center relative py-8 flex-1">
<div className="relative z-10">
{configShow.info && <Info />}
{configShow.servers && <Servers />}
{configShow.operations && <Operations />}
{configShow.messages && <Messages />}
{configShow.schemas && <Schemas />}
</div>
<div className="panel--right absolute top-0 right-0 h-full bg-gray-800" />
</div>
</div>
</SpecificationContext.Provider>
) : (
configShow.errors && error && <Error error={error} />
)}
</section>
</ConfigContext.Provider>
);
which yeilds the same effect.
Let me know your thoughts on this.
Thanks for highlighting that. Have put some logic to rerender the component fresh. |
…i-react into ErrorBoundary-in-layout
Quality Gate passedIssues Measures |
Description
As proposed and discussed here #1101 (comment).
Changes proposed in this pull request:
Added an error boundary in layout to handle errors generated by infinite recursion and such so that the application doesnt crash into an irrecoverable state.
Reused the already existing Error component to render error,
Related issue(s)
#1100