-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(subscribe): don't swallow internal errors #4089
Conversation
|
src/internal/util/reportError.ts
Outdated
@@ -0,0 +1,34 @@ | |||
import { Subscriber } from '../Subscriber'; |
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.
Since this is only used in one spot, you can just inline everything in that one spot. It'll perform better, and will be more readable (if a little harder to test)
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.
For tests, I'd rather just have more integration/functional tests of this.
src/internal/util/reportError.ts
Outdated
return true; | ||
} | ||
|
||
function consoleReportError(err: any): void { |
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.
consoleWarn
, this is too confusing considering we have a hostReportError
function in the library, which is different.
@benlesh I've made a bunch of changes inline with your requests:
|
The build is failing✨ Good work on this PR so far! ✨ Unfortunately, the Travis CI build is failing as of 30440d2. Here's the output:
|
src/internal/util/canReportError.ts
Outdated
const { closed, destination, isStopped } = observer as any; | ||
if (closed || isStopped) { | ||
return false; | ||
} else if (destination instanceof Subscriber || (destination && destination[rxSubscriberSymbol])) { |
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.
use isTrustedSubscriber
src/internal/util/canReportError.ts
Outdated
* need to be reported via a different mechanism. | ||
* @param observer the observer | ||
*/ | ||
export function canReportError(observer: ErrorObserver<any>): boolean { |
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 should always be a Subscriber
of some sort.
src/internal/util/consoleWarn.ts
Outdated
@@ -0,0 +1,7 @@ | |||
export function consoleWarn(...args: any[]): void { | |||
if (console.warn) { |
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.
We shouldn't have to check this every time the function is called.
export const consoleWarn = console.warn ? console.warn.bind(console) : console.log.bind(console);
Looking good, just a couple of nits. |
@benlesh I've made changes inline with your requests:
However, I've not changed
I could replace it with: export const consoleWarn = console.warn ?
(...args: any[]) => console.warn(...args) :
(...args: any[]) => console.log(...args); But I cannot see that making a discernible difference. |
|
which version of RxJs will this be included? |
Description:
This PR reports errors that would otherwise be swallowed - because of a closed subscriber - to the console. (This behaviour is something that bit me again, today, when I was investigating a snippet that effected a stack overflow error in v5, but didn't effect the error in v6. The error was still occurring, of course, it just wasn't being thrown.)
As discussed in the linked issue, calling
hostReportError
would be preferred - rather than writing to the console - but doing so would be a breaking change.Related issue (if exists): #3803