Skip to content

Commit

Permalink
fix(Schedulers): Throwing a falsy error in a scheduled function no lo…
Browse files Browse the repository at this point in the history
…nger results in strange error objects. (#6594)

* chore: fix TS 4.4 build in CI

* chore: improve message
  • Loading branch information
benlesh committed Sep 14, 2021
1 parent 9a40869 commit c70fcc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
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;
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) {
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('Scheduled action threw falsy error');
}
if (errored) {
this.unsubscribe();
Expand Down

0 comments on commit c70fcc0

Please sign in to comment.