File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -710,9 +710,16 @@ class DatastoreRequest {
710710 query = extend ( true , new Query ( ) , query ) ;
711711
712712 const makeRequest = ( query : Query ) => {
713- const reqOpts : RequestOptions = {
714- query : entity . queryToQueryProto ( query ) ,
715- } ;
713+ const reqOpts = { } as RequestOptions ;
714+
715+ try {
716+ reqOpts . query = entity . queryToQueryProto ( query ) ;
717+ } catch ( e ) {
718+ // using setImmediate here to make sure this doesn't throw a
719+ // synchronous error
720+ setImmediate ( onResultSet , e ) ;
721+ return ;
722+ }
716723
717724 if ( options . consistency ) {
718725 const code = CONSISTENCY_PROTO_CODE [ options . consistency . toLowerCase ( ) ] ;
Original file line number Diff line number Diff line change @@ -819,6 +819,18 @@ describe('Request', () => {
819819 } )
820820 . emit ( 'reading' ) ;
821821 } ) ;
822+
823+ it ( 'should emit an error when encoding fails' , done => {
824+ const error = new Error ( 'Encoding error.' ) ;
825+ sandbox . stub ( entity , 'queryToQueryProto' ) . throws ( error ) ;
826+ request
827+ . runQueryStream ( { } )
828+ . on ( 'error' , ( err : Error ) => {
829+ assert . strictEqual ( err , error ) ;
830+ done ( ) ;
831+ } )
832+ . emit ( 'reading' ) ;
833+ } ) ;
822834 } ) ;
823835
824836 describe ( 'success' , ( ) => {
You can’t perform that action at this time.
0 commit comments