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(Schedulers): Throwing a falsy error in a scheduled function no longer results in strange error objects. #6594

Merged
merged 2 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/schedulers/QueueScheduler-spec.ts
Expand Up @@ -63,7 +63,7 @@ describe('Scheduler.queue', () => {
const actions: Subscription[] = [];
let action2Exec = false;
let action3Exec = false;
let errorValue = undefined;
let errorValue: any = undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

To fix CI ts@latest

try {
queue.schedule(() => {
actions.push(
Expand Down
11 changes: 7 additions & 4 deletions spec/util/UnsubscriptionError-spec.ts
Expand Up @@ -16,10 +16,13 @@ describe('UnsubscriptionError', () => {
try {
subscription.unsubscribe();
} catch (err) {
expect(err instanceof UnsubscriptionError).to.equal(true);
expect(err.errors).to.deep.equal([err1, err2]);
expect(err.name).to.equal('UnsubscriptionError');
expect(err.stack).to.be.a('string');
if (err instanceof UnsubscriptionError) {
Copy link
Member Author

Choose a reason for hiding this comment

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

To fix CI ts@latest

expect(err.errors).to.deep.equal([err1, err2]);
expect(err.name).to.equal('UnsubscriptionError');
expect(err.stack).to.be.a('string');
} else {
throw new TypeError('Invalid error type');
}
}
});
});
5 changes: 4 additions & 1 deletion src/internal/scheduler/AsyncAction.ts
Expand Up @@ -116,7 +116,10 @@ export class AsyncAction<T> extends Action<T> {
this.work(state);
} catch (e) {
errored = true;
errorValue = (!!e && e) || new Error(e);
// HACK: Since code elsewhere is relying on the "truthiness" of the
// return here, we can't have it return "" or 0 or false.
// TODO: Clean this up when we refactor schedulers mid-version-8 or so.
errorValue = e ? e : new Error('Falsy action error');
Copy link
Member Author

Choose a reason for hiding this comment

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

To fix CI ts@latest and correct a weird bit of code that TS 4.4 helped catch.

}
if (errored) {
this.unsubscribe();
Expand Down