Skip to content
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
13 changes: 10 additions & 3 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,16 @@ class DatastoreRequest {
query = extend(true, new Query(), query);

const makeRequest = (query: Query) => {
const reqOpts: RequestOptions = {
query: entity.queryToQueryProto(query),
};
const reqOpts = {} as RequestOptions;

try {
reqOpts.query = entity.queryToQueryProto(query);
} catch (e) {
// using setImmediate here to make sure this doesn't throw a
// synchronous error
setImmediate(onResultSet, e);
return;
}

if (options.consistency) {
const code = CONSISTENCY_PROTO_CODE[options.consistency.toLowerCase()];
Expand Down
12 changes: 12 additions & 0 deletions test/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,18 @@ describe('Request', () => {
})
.emit('reading');
});

it('should emit an error when encoding fails', done => {
const error = new Error('Encoding error.');
sandbox.stub(entity, 'queryToQueryProto').throws(error);
request
.runQueryStream({})
.on('error', (err: Error) => {
assert.strictEqual(err, error);
done();
})
.emit('reading');
});
});

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