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: return errors from Query.stream() #1046

Merged
merged 1 commit into from
Apr 25, 2020
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
2 changes: 1 addition & 1 deletion dev/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ export class Query<T = DocumentData> {
});

responseStream.pipe(transform);
responseStream.on('error', transform.destroy);
responseStream.on('error', e => transform.destroy(e));
return transform;
}

Expand Down
33 changes: 31 additions & 2 deletions dev/test/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import * as chaiAsPromised from 'chai-as-promised';
import * as extend from 'extend';

import {google} from '../protos/firestore_v1_proto_api';
import {FieldPath, FieldValue, Firestore, setLogFunction} from '../src';
import {
FieldPath,
FieldValue,
Firestore,
QueryDocumentSnapshot,
setLogFunction,
} from '../src';
import {DocumentData, DocumentReference, Query, Timestamp} from '../src';
import {setTimeoutHandler} from '../src/backoff';
import {DocumentSnapshot, DocumentSnapshotBuilder} from '../src/document';
Expand Down Expand Up @@ -558,7 +564,7 @@ describe('query interface', () => {
});
});

it('handles stream exception after initialization', () => {
it('handles stream exception after initialization (with get())', () => {
const overrides: ApiOverride = {
runQuery: () => {
return stream(result('first'), new Error('Expected error'));
Expand All @@ -578,6 +584,29 @@ describe('query interface', () => {
});
});

it('handles stream exception after initialization (with stream())', done => {
const overrides: ApiOverride = {
runQuery: () => {
return stream(result('first'), new Error('Expected error'));
},
};

createInstance(overrides).then(firestore => {
const result = firestore.collection('collectionId').stream();

let resultCount = 0;
result.on('data', doc => {
expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot);
++resultCount;
});
result.on('error', err => {
expect(resultCount).to.equal(1);
expect(err.message).to.equal('Expected error');
done();
});
});
});

it('streams results', callback => {
const overrides: ApiOverride = {
runQuery: request => {
Expand Down