Skip to content
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(errors): Custom RxJS errors now all have a call stack #5686

Merged

Conversation

benlesh
Copy link
Member

@benlesh benlesh commented Sep 1, 2020

NOTE: Because we have to workaround compilation-to-ES5 inadequacies until call stack locations will show as being inside of the constructor implementation at the top level. This will go away as we are able to move the community to ES2015+

BREAKING CHANGE: Tests that are written with naive expectations against errors may fail now that errors have a proper stack property. In some testing frameworks, a deep equality check on two error instances will check the values in stack, which could be different.

fixes #4250

@@ -0,0 +1,15 @@
/** @prettier */

export function createErrorClass<T>(name: string, setup: (this: Error, ...args: any[]) => void): T {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm going to add a doc comment about why this exists.


/** @test {concat} */
describe('concat operator', () => {
let rxTest: TestScheduler;

beforeEach(() => {
rxTest = new TestScheduler(assertDeepEquals);
rxTest = new TestScheduler(observableMatcher);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: These had to be changed, because a simple deep-equals check fails for expect(new CustomError()).to.deep.equal(new CustomError()) once call stacks are in the mix.

const MySpecialError: any = createErrorClass(
(_super) =>
function MySpecialError(this: any, arg1: number, arg2: string) {
_super(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: would it be cleaner to call _super(this, 'Super special error') instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_super is probably a bad name, I'm just not sure what else to call it. :\

src/internal/observable/dom/AjaxObservable.ts Outdated Show resolved Hide resolved
src/internal/util/UnsubscriptionError.ts Outdated Show resolved Hide resolved
NOTE: Because we have to workaround compilation-to-ES5 inadequacies until call stack locations will show as being inside of the constructor implementation at the top level. This will go away as we move the community to ES2015+

BREAKING CHANGE: Tests that are written with naive expectations against errors may fail now that errors have a proper `stack` property. In some testing frameworks, a deep equality check on two error instances will check the values in `stack`, which could be different.

fixes ReactiveX#4250
@benlesh benlesh force-pushed the Issue-4250-errors-missing-stack-traces branch from 3a8e531 to ac7aa52 Compare September 3, 2020 12:55
@benlesh benlesh merged commit 9bb046c into ReactiveX:master Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors do not get stack traces in 6.3.x
2 participants