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

MLIBZ-2323: Thrown error in onNext() in observable causes silent observable unsubscribe #302

Merged
merged 3 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/core/datastore/cachestore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ describe('CacheStore', () => {
});
});

it('should throw an error if trying to access a property on undefined', (done) => {
const store = new CacheStore(collection);
const onNextSpy = expect.createSpy();

store.find()
.subscribe((entities) => {
return entities[0].name;
}, (error) => {
try {
expect(error).toBeA(TypeError);
done();
} catch (e) {
done(e);
}
}, () => {
done(new Error('This test should fail.'));
});
});

it('should return the entities', (done) => {
const entity1 = { _id: randomString() };
const entity2 = { _id: randomString() };
Expand Down
2 changes: 1 addition & 1 deletion src/core/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SafeSubscriber extends Subscriber {
try {
fn.call(this._context, value);
} catch (err) {
this.unsubscribe();
this.error(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to throw an error here. But are there certain cases where we should still unsubscribe, or is this now something the developer should handle completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will still unsubscribe after the error callback is called.

throw err;
}
}
Expand Down