Can an error boundary prevent React's error logging?
See original GitHub issueI noticed this unconditional console.error
which I’d like to prevent to keep the console clean from errors that are already “caught” in an error boundary.
Maybe a condition on capturedError.errorBoundaryFound
could prevent this logging?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:37
- Comments:30 (3 by maintainers)
Top Results From Across the Web
Error Boundaries - React
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI...
Read more >React error handling with react-error-boundary - LogRocket Blog
So error boundaries only catch errors that occur in a lifecycle method, render method, and inside Hooks like useEffect . According to the...
Read more >React Error Handling and Logging Best Practices
Error boundaries are the most straightforward and effective way to handle errors that occur within your React components. You can create an ...
Read more >React Error Handling And Reporting With Error Boundary And ...
As we can see from our component tree, the error boundary itself is a React component. According to the docs,. A class component...
Read more >React Logging and Error Handling Best Practices - Tek-Tools
Without error boundaries, exceptions can cascade throughout your application and crash your React app. They act as a fence around a component to ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gaearon
consider the following production issue we are facing: We are using a third party logging service, that logs all
console.error
calls automagically- which is debatably awesome and at the same time a given fact.Naturally, we have our own ErrorBoundary implementation: We want to slap on extra information special to the boundary instance- So our error boundary component receives this information as props / context, And logs the error along this information using the third party’s sdk when an error occurs.
As a result of this implementation, when a component fails, we have two separate errors logged in our monitoring pipeline: One which react logs, with barely any info, which comes from
console.error
And one with everything we need to know, which we explicitly logged via the third party library.Since this redundancy is confusing and not acceptable We are now facing quite a dilemma:
If we don’t explicitly log, we lose error specific info. We also rely on react to do the logging for us, which is a bad idea in the long run.
if we explicitly log - we get two separate events in our monitoring pipeline, which is confusing and noisy, since our monitoring pipeline is automated and triggers a whole lot of internal processes.
I bet that we both believe
console.error
to be a side effect. As an app developer, wouldn’t you agree with me that such a side effect should not be invoked by a UI library without the possibility to opt out?It’s great that I can isolate failures to granular regions in the application- anything other than that, should not be decided for me as a developer. I wouldn’t want to see anything in the console which I did not put there. Especially if it renders the entire stack of my component tree structure, uglified or not.
On the other hand, I do understand where you’re coming from by saying you don’t want it to be easy to swallow errors, so how about this as middle ground: You could move the invocation of
console.error
tocomponentDidCatch
, Which would be the default implementation unless overriden.if you think of it, this is the correct thing to do, since
componentDidCatch
is meant for exactly this. To quote the docs:you say
console.error
and I saythirdPartyLibrary.logError
.The means of logging should be up to app developers, especially if they went through the trouble of setting up Error Boundaries.
Since Error Boundaries are basically logging components with some conditional rendering, and since I bet our logging provider is not the only one which logs
console.error
calls, wouldn’t you say this issue should be solved in a more extensible manner?As for buggy error boundaries, IMHO, you should not care about them. It’s just another failed component, so let it fail until it either crashes the entire tree or another boundary catches it. Since react is solely a UI rendering library, why should it decide what happens when rendering fails?
Don’t close. We can’t seriously unconditionally log this anymore.