-
Notifications
You must be signed in to change notification settings - Fork 405
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(store): implement NGXS unhandled error handler #2137
Conversation
a1142ce
to
21a1641
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 19c4b4f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
21a1641
to
4dabcae
Compare
BundleMon (Integration Projects)Files updated (2)
Total files change +152B +0.11% Final result: ✅ View report in BundleMon website ➡️ |
2687750
to
37d6200
Compare
8922e9e
to
a1a872d
Compare
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 work here!
A few comments.
And just wondering if the original issue is represented in a test?
import { leaveNgxs } from '../operators/leave-ngxs'; | ||
import { executeUnhandledCallback } from './unhandled-rxjs-error-callback'; | ||
|
||
function fallbackErrorHandler<T>(ngZone: NgZone) { |
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.
A very important aspect of this operator is the fact that it subscribes. We could call it fallbackSubscriber
. WDYT? It should also move to another file.
return new Observable<T>(subscriber => { | ||
realSubscriber = true; | ||
// Now that there is a real subscriber, we can unsubscribe our pro-active subscription | ||
subscription.unsubscribe(); |
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 might be called multiple times if there are multiple real subscribers. I think it is just a no-op, but haven't tested it.
We could set it to null after unsubscribing (and change this line to use ?.
).
Having a falsy subscription could also be the indicator of whether or not we have a real subscriber.
// Since the error can be essentially anything, we must ensure that we only | ||
// handle objects, as weak maps do not allow any other key type besides objects. | ||
// The error can also be a string if thrown in the following manner: `throwError('My Error')`. | ||
if (error !== null && typeof error === 'object') { |
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.
Do we need a strategy for handling non-object 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.
I don't think so. Here's why:
- the ecma 2022 standard specifies the
Error
class which is intended to represent errors - while other types are technically allowed in
throw
statements, such asthrow some_string
, it's widely regarded as bad practice. This is because it doesn't include stack trace information, making debugging more difficult and less informative
|
||
handleError(_error: any, _context: NgxsErrorContext): void { | ||
// Retrieve lazily to avoid cyclic dependency exception. | ||
this._errorHandler = this._errorHandler || this._injector.get(ErrorHandler); |
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.
Given the other changes to load this lazily in the StateFactory, we should move this back to the constructor.
This would also be closer to what a user may implement.
'Action 1 - dispatch complete', | ||
'action1 obs - unsubscribe', | ||
'Action 1 - dispatch complete', |
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 change because we unsubscribe before subscribing the real subscriber.
Would it go back to what it was if we unsubscribed after adding the real subscriber (in the fallback operator) ?
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 change is related to RxJS upgrade, seems like the sequence of some stuff has changed internally
a1a872d
to
6657abb
Compare
Code Climate has analyzed commit 19c4b4f and detected 1 issue on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 91.7% (50% is the threshold). This pull request will bring the total coverage in the repository to 95.2% (0.0% change). View more on Code Climate. |
The original issue was that the error handler was not being called on each error. We've decided not to support this anymore because it's strange to log errors even if they're handled. For instance, if someone is using Rollbar and providing their custom |
No description provided.