-
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9a309c0
chore(reportError): implement reportError
cartant ff3f06e
fix(subscribe): don't swallow internal errors
cartant 6801bbd
chore(reportError): remove console.log from test
cartant 506eb42
chore(reportError): test destination is Subscriber
cartant ec98f5b
test(reportError): use closed observer
cartant 936b26b
chore(reportError): test subscriber symbol too
cartant 1ed1339
chore(reportError): fix logic
cartant e4959af
chore(reportError): rename to consoleWarn
cartant 669ee9c
test(reportError): stub the console
cartant 3ee03c0
chore(reportError): fix whitespace
cartant 9d8cb76
refactor(reportError): use canReportError instead
cartant bc8f54c
refactor(canReport): remove recursion
cartant 1a9d49a
test(subscribe): test internal error reporting
cartant bbfaed0
test(bindCallback): test error reporting
cartant 1fd1807
test(bindNodeCallback): test error reporting
cartant 6f40412
chore(canReport): fix JSDoc
cartant daa02c4
chore(test): fix test description
cartant ed2a617
test(canReport): use noop error handlers
cartant 1b53211
chore(canReport): use isTrustedSubscriber
cartant 30440d2
chore(canReport): restrict observer type
cartant d640e9d
chore(canReport): fix tests
cartant 14a6c61
chore(canReport): use console.warn directly
cartant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect } from 'chai'; | ||
import { noop, Subscriber } from 'rxjs'; | ||
import { empty } from 'rxjs/internal/Observer'; | ||
import { canReportError } from 'rxjs/internal/util/canReportError'; | ||
|
||
describe('canReportError', () => { | ||
it('should report errors to an observer if possible', () => { | ||
const subscriber = new Subscriber(noop, noop); | ||
expect(canReportError(subscriber)).to.be.true; | ||
}); | ||
|
||
it('should not report errors to a stopped observer', () => { | ||
const subscriber = new Subscriber(noop, noop); | ||
subscriber.error(new Error('kaboom')); | ||
expect(canReportError(subscriber)).to.be.false; | ||
}); | ||
|
||
it('should not report errors to a closed observer', () => { | ||
expect(canReportError(empty)).to.be.false; | ||
}); | ||
|
||
it('should not report errors an observer with a stopped destination', () => { | ||
const destination = new Subscriber(noop, noop); | ||
const subscriber = new Subscriber(destination); | ||
destination.error(new Error('kaboom')); | ||
expect(canReportError(subscriber)).to.be.false; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Subscriber } from '../Subscriber'; | ||
import { rxSubscriber as rxSubscriberSymbol } from '../symbol/rxSubscriber'; | ||
import { ErrorObserver } from '../types'; | ||
|
||
/** | ||
* Determines whether the ErrorObserver is closed or stopped or has a | ||
* destination that is closed or stopped - in which case errors will | ||
* need to be reported via a different mechanism. | ||
* @param observer the observer | ||
*/ | ||
export function canReportError(observer: ErrorObserver<any>): boolean { | ||
while (observer) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
observer = destination; | ||
} else { | ||
observer = null; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe 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); |
||
console.warn(...args); | ||
} else { | ||
console.log(...args); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.