-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(subscribe): report errors that occur in subscribe after the initi…
…al error (#4089) * chore(reportError): implement reportError * fix(subscribe): don't swallow internal errors Closes #3803 * chore(reportError): remove console.log from test * chore(reportError): test destination is Subscriber * test(reportError): use closed observer * chore(reportError): test subscriber symbol too * chore(reportError): fix logic * chore(reportError): rename to consoleWarn * test(reportError): stub the console * chore(reportError): fix whitespace * refactor(reportError): use canReportError instead * refactor(canReport): remove recursion * test(subscribe): test internal error reporting * test(bindCallback): test error reporting * test(bindNodeCallback): test error reporting * chore(canReport): fix JSDoc * chore(test): fix test description * test(canReport): use noop error handlers * chore(canReport): use isTrustedSubscriber * chore(canReport): restrict observer type * chore(canReport): fix tests * chore(canReport): use console.warn directly
- Loading branch information
Showing
9 changed files
with
114 additions
and
5 deletions.
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,29 @@ | ||
import { expect } from 'chai'; | ||
import { noop, Subject, Subscriber } from 'rxjs'; | ||
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 subject', () => { | ||
const subject = new Subject<{}>(); | ||
subject.unsubscribe(); | ||
expect(canReportError(subject)).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
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,22 @@ | ||
import { isTrustedSubscriber, Subscriber } from '../Subscriber'; | ||
import { Subject } from '../Subject'; | ||
|
||
/** | ||
* 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: Subscriber<any> | Subject<any>): boolean { | ||
while (observer) { | ||
const { closed, destination, isStopped } = observer as any; | ||
if (closed || isStopped) { | ||
return false; | ||
} else if (destination && isTrustedSubscriber(destination)) { | ||
observer = destination; | ||
} else { | ||
observer = null; | ||
} | ||
} | ||
return true; | ||
} |