Skip to content

Commit

Permalink
fix: return errors from Query.stream() (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Apr 25, 2020
1 parent d13b9a6 commit 4b65fca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
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

0 comments on commit 4b65fca

Please sign in to comment.