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

Include error stack in <ErrorBoundary> #1512

Merged
merged 7 commits into from
Mar 1, 2021
Merged

Conversation

rasmuswoelk
Copy link
Member

Until now, we have only been rendering the component stack, when the <ErrorBoundary> catches an error.

This update includes the error stack as well which makes it a lot easier to pinpoint where an error occurred at first glance without having to look in the console.

Note

The component stack can be made more precise by wrapping each module in an <ErrorBoundary>.

Before

Screenshot 2021-02-18 at 15 15 21

After

Screenshot 2021-02-18 at 14 59 12

Copy link
Contributor

@MikeTaylor MikeTaylor left a comment

Choose a reason for hiding this comment

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

This is useful, because it adds information. That's always good.

But in fact I'd been under the impression that I was seeing a lower-level stack than the one I wanted, which is at the component level! So you're adding the thing I thought I already had, and I already had (apparently) the thing I thought I wanted!

I gotta go and lie down.

${componentStack.toString()}
`.split('\n')
// Remove empty lines
.filter(str => !!str);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.filter(str => !!str);
.filter(Boolean);

Copy link
Member

Choose a reason for hiding this comment

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

.filter(Boolean);

Is using the Boolean constructor in this way a common idiom? I mean, I get it, it works, it's a tiny bit shorter. But given .filter() expects to receive a function and Boolean looks nothing like a function, it seems less clear rather than more.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought it is kinda idiom. Met this many times.
Like https://michaeluloth.com/filter-boolean

Copy link
Member

Choose a reason for hiding this comment

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

Fair. Maybe it's the idiomatic way now, but it wasn't when I learned Javascript back in the 90s 😆 .

netscape

Copy link
Contributor

Choose a reason for hiding this comment

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

Who at that time could have known that the language for making falling snowflakes could become the world #1

Copy link
Member

@zburke zburke left a comment

Choose a reason for hiding this comment

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

Hmm, this is different, but unfortunately it's not actually better. I really appreciate the effort though! The error stack is definitely more interesting than the component stack but unless we can show source-mapped line numbers, it still isn't actionable information.

In development mode running yarn local to serve from a workspace, the error stack shows line numbers from the bundle rather than from the original source, which is what we get in the console:

Screen Shot 2021-02-19 at 7 52 35 AM (2)

Likewise, in production when serving from a build with sourcemaps enabled, the "Error details" panel appears to still show the component stack. In order for that "Copy" button to copy actionable information, it would need to show the error stack with source-mapped line numbers like the console:

Screen Shot 2021-02-19 at 8 32 58 AM (2)

@zburke
Copy link
Member

zburke commented Feb 19, 2021

The component stack can be made more precise by wrapping each module in an <ErrorBoundary>.

Aren't they already?

        return modules.app.map((module) => {
          ...
          return (
            ...
                        <RouteErrorBoundary
                          escapeRoute={module.home}
                          moduleName={displayName}
                          stripes={moduleStripes}
                        >
                            ...

@rasmuswoelk
Copy link
Member Author

@zburke You are right – the development error could be a lot more precise. And the production error is basically useless because of the obfuscation.

I found this issue where multiple sugested solutions:
facebook/create-react-app#6667

Here are some of them:

And correct, the modules are wrapped in stripes-core, but I noticed that wrapping the root of the module results in a more precise and relevant component stack (in development at least).

@id-jenkins

This comment has been minimized.

@sonarcloud
Copy link

sonarcloud bot commented Feb 25, 2021

@rasmuswoelk
Copy link
Member Author

Merging this for now. We can improve on the readability of the stack traces later.

@rasmuswoelk rasmuswoelk merged commit 70a7548 into master Mar 1, 2021
@zburke zburke deleted the improve-error-boundary branch April 7, 2021 18:01
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.

5 participants