Skip to content

Commit

Permalink
feat: Remove "super gross mode" once and for all! `useDeprecatedSynch…
Browse files Browse the repository at this point in the history
…ronousErrorHandling` is removed (#6595)

* feat: Remove "super gross mode" once and for all! `useDeprecatedSynchronousErrorHandling` is removed

BREAKING CHANGE: Removed `useDeprecatedSynchronousErrorHandling`. No workarounds for this.

* chore: update api_guardian files

* chore: remove unnecessary comment

* chore: update api_guardian files
  • Loading branch information
benlesh committed Sep 19, 2021
1 parent 8233648 commit 5225692
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 504 deletions.
1 change: 0 additions & 1 deletion api_guard/dist/types/index.d.ts
Expand Up @@ -277,7 +277,6 @@ export declare function generate<T, S>(options: GenerateOptions<T, S>): Observab
export interface GlobalConfig {
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
onUnhandledError: ((err: any) => void) | null;
useDeprecatedSynchronousErrorHandling: boolean;
}

export declare function groupBy<T, K>(key: (value: T) => K, options: BasicGroupByOptions<K, T>): OperatorFunction<T, GroupedObservable<K, T>>;
Expand Down
222 changes: 0 additions & 222 deletions spec/Observable-spec.ts
Expand Up @@ -591,228 +591,6 @@ describe('Observable', () => {
});
expect(caught).to.be.true;
});


describe('if config.useDeprecatedSynchronousErrorHandling === true', () => {
beforeEach(() => {
config.useDeprecatedSynchronousErrorHandling = true;
});

it('should throw synchronously', () => {
expect(() => throwError(() => new Error('thrown error')).subscribe()).to.throw(Error, 'thrown error');
});

it('should rethrow if next handler throws', () => {
const observable = new Observable((observer) => {
observer.next(1);
});

const sink = Subscriber.create(() => {
throw 'error!';
});

expect(() => {
observable.subscribe(sink);
}).to.throw('error!');
});


// From issue: https://github.com/ReactiveX/rxjs/issues/5979
it('should still rethrow synchronous errors from next handlers on synchronous observables', () => {
expect(() => {
of('test').pipe(
// Any operators here
map(x => x + '!!!'),
map(x => x + x),
map(x => x + x),
map(x => x + x),
).subscribe({
next: () => {
throw new Error(
'hi there!'
)
}
})
}).to.throw('hi there!');
});

it('should rethrow synchronous errors from flattened observables', () => {
expect(() => {
of(1)
.pipe(concatMap(() => throwError(() => new Error('Ahoy! An error!'))))
.subscribe(console.log);
}).to.throw('Ahoy! An error!');

expect(() => {
of(1)
.pipe(switchMap(() => throwError(() => new Error('Avast! Thar be a new error!'))))
.subscribe(console.log);
}).to.throw('Avast! Thar be a new error!');
});

it('should teardown even with a synchronous error', () => {
let called = false;
const badObservable = new Observable((subscriber) => {
subscriber.add(() => {
called = true;
});

subscriber.error(new Error('bad'));
});

try {
badObservable.subscribe();
} catch (err) {
// do nothing
}
expect(called).to.be.true;
});

it('should teardown even with a synchronous thrown error', () => {
let called = false;
const badObservable = new Observable((subscriber) => {
subscriber.add(() => {
called = true;
});

throw new Error('bad');
});

try {
badObservable.subscribe();
} catch (err) {
// do nothing
}
expect(called).to.be.true;
});


it('should handle empty string sync errors', () => {
const badObservable = new Observable(() => {
throw '';
});

let caught = false;
try {
badObservable.subscribe();
} catch (err) {
caught = true;
expect(err).to.equal('');
}
expect(caught).to.be.true;
});

it('should execute finalize even with a sync error', () => {
let called = false;
const badObservable = new Observable((subscriber) => {
subscriber.error(new Error('bad'));
}).pipe(
finalize(() => {
called = true;
})
);

try {
badObservable.subscribe();
} catch (err) {
// do nothing
}
expect(called).to.be.true;
});

it('should execute finalize even with a sync thrown error', () => {
let called = false;
const badObservable = new Observable(() => {
throw new Error('bad');
}).pipe(
finalize(() => {
called = true;
})
);

try {
badObservable.subscribe();
} catch (err) {
// do nothing
}
expect(called).to.be.true;
});

it('should execute finalize in order even with a sync error', () => {
const results: any[] = [];
const badObservable = new Observable((subscriber) => {
subscriber.error(new Error('bad'));
}).pipe(
finalize(() => {
results.push(1);
}),
finalize(() => {
results.push(2)
})
);

try {
badObservable.subscribe();
} catch (err) {
// do nothing
}
expect(results).to.deep.equal([1, 2]);
});

it('should execute finalize in order even with a sync thrown error', () => {
const results: any[] = [];
const badObservable = new Observable(() => {
throw new Error('bad');
}).pipe(
finalize(() => {
results.push(1);
}),
finalize(() => {
results.push(2)
})
);

try {
badObservable.subscribe();
} catch (err) {
// do nothing
}
expect(results).to.deep.equal([1, 2]);
});

// https://github.com/ReactiveX/rxjs/issues/6271
it('should not have a run-time error if no errors are thrown and there are operators', () => {
expect(() => {
of(1, 2, 3).pipe(
map(x => x + x),
map(x => Math.log(x))
)
.subscribe();
}).not.to.throw();
});

it('should call teardown if sync unsubscribed', () => {
let called = false;
const observable = new Observable(() => () => (called = true));
const subscription = observable.subscribe();
subscription.unsubscribe();

expect(called).to.be.true;
});

it('should call registered teardowns if sync unsubscribed', () => {
let called = false;
const observable = new Observable((subscriber) => subscriber.add(() => called = true));
const subscription = observable.subscribe();
subscription.unsubscribe();

expect(called).to.be.true;
});

afterEach(() => {
config.useDeprecatedSynchronousErrorHandling = false;
});
});
});

describe('pipe', () => {
Expand Down

0 comments on commit 5225692

Please sign in to comment.