-
Notifications
You must be signed in to change notification settings - Fork 465
Added improved method of logging errors #674
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
Conversation
|
Thanks for the PR! <3 I believe console.error still isn't safe to use broadly if we want to support IE 8 and 9--I believe they only provide them if the dev tools are open, and we wouldn't want to not emit an error. Also I don't believe console.error triggers window.onerror unfortunately. We could do We'd have to modify the error message string itself though and that feels dirty too. Overall I'm squeamish and not sure if there's a general purpose approach we can do. Maybe we could get away with providing something in dev-mode only, which seems much more safe? e.g. we rethrow the error, but also provide a console.warn or console.error (when available) that provide more context and a link to a new doc page about various patterns for handling errors? That would be similar to what I was planning to do here: #94 (comment) except this might have to be done at the combineEpics level so we have Still, we could provide a way to turn off the warning, and/or combineEpics isn't particularly complicated if someone wanted to reimplement it without the warning code. These sorts of "but what if" issues are why I haven't made any of these yet. Especially since people can pretty easily do it themselves if they'd like, though of course defaults are nice and not everyone realizes how. I dunno, what do you think about my points? |
|
Oh forgot to add: this is mostly to be an unfortunate side effect of how RxJS (and nearly all similar lazy libs) work; the call stack being an internal one rather than your original source location where you declared the chain of operators. Not that we shouldn't consider adding help when we can. |
This method makes it obvious which epic actually threw an error and then throws it again so it proceeds as usual similar to doing a `Promise.prototype.catch` and throwing the error again so the next `.catch` picks it up. Just like when throwing a `TypeError`, this also utilizes `epic.name`.
|
I get what you mean. I like the idea of using Previous ProjectsOn the projects I've worked, I never considered adding a catch-all until today (2 years later). I always had trouble figuring out where an error was occurring and this was always trouble when telling people about the benefits of RxJS and Redux-Observable. Another method I've done is create a ReasoningThat's why I prefer There's also the possibility of creating a separate If other people are compensating for this bug like you said, I bet they'd rather this solution instead since it's more granular. Global Error-Catching PRIn your other PR (#94), it appears the goal is making sure Redux-Observable keeps going so an error doesn't kill off a bunch of epics down the chain right? It seems like what you were planning there would work fine even with this PR but does change the functionality quite a bit. I've had epics fail before and take everything down with them. I've also had epics error and stop working, but everything else worked fine so I wasn't aware of an issue. As long as we can get something in there to show runtime errors, it'll be significantly easier to debug when these issues occur. |
Since `console.error` isn't compatible in all browsers (such as older IE8 and 9), this has been limited to only error when it's available.
The current consensus was that we would not in fact retry, we would only log the error. See my last comment: #94 (comment) |
|
Cool. What's the consensus on this PR? Do I just need to make adding the |
|
If this is optional and/or only in dev it's fine by me. |
|
I'd prefer a config var so, by default, this would be enabled and people could disable it as-needed, but there are some issues doing so:
For now, I've simply restricted it to development mode. This is the minimal-changes-needed version which will hold until a v2 where you could get away with API changes. Unless it's arleady there, we'll need documentation talking about adding |
|
If this is good to go, can someone merge it? |
|
@Sawtaytoes not good to go yet. Sorry, not sure when I'll have time to dig deep about this and the implications to make a decision. There will likely need to be adjustments but I don't want to keep having your go back and forth until I figure them all out. e.g. |
|
Have you had a chance to look into this @jayphelps? I don't mind making changes that suit the project. I'd like to make Redux-Observable something really easy for people to debug as soon as possible. I've already got new buddies starting to use it on their teams and better debugging would be super helpful. |
|
Closing old PRs. As always thank you for your contribution. |
Reason for PR
I noticed
combineEpicsdoesn't do anything to help locate errors. Almost always, when using redux-observable, it's nearly impossible to find errors unless you've got acatchErrorat the bottom of your pipeline.In my own Redux-less implementation of Redux-Observable, I added this functionality:
createRootEpiccatchEpicErrorNot only does this implementation include a way of logging errors as actions, it also logs them to the console with the name of the Epic that caused the error.
It's super helpful in debugging.
combineEpicscould definitely benefit from functionality like this.In case there's a stack available such as the error being an
EventError(Node.js), one of my other versions of this operator checks for stack information.Changes
This method makes it obvious which epic actually threw an error and then throws it again so it proceeds as usual similar to doing a
Promise.prototype.catchand throwing the error again so the next.catchpicks it up.Just like when throwing a
TypeError, this also utilizesepic.name.