Skip to content

Uncatchable error is thrown if undefined is given on query filter (JS built version) #491

@godjirax

Description

@godjirax

Environment details

  • OS: macOS Mojave
  • Node.js version: v10.16.0
  • npm version: 6.9.0
  • @google-cloud/datastore version: 4.2.0
  • Built version

Steps to reproduce

If we give undefined to a query filter, an uncatchable error is thrown: Error: Unsupported field value, undefined, was provided., and program crashes.

Problem occurs only in built version, because Typescript doesn't compile with this scenario:

let query = new FakeQuery();
query.namespace = 'namespace';
query = extend(true, new FakeQuery(), query);
query.filter('myfield', undefined); // => error TS2345: Argument of type 'undefined' is not assignable to parameter of type '{}'.

To be able to catch the error, the library instead of doing:

// src/request/ts: l.788
stream.once('reading', () => {
  makeRequest(query);
});

could do this:

// src/request/ts: l.788
stream.once('reading', () => {
  try {
    makeRequest(query);
  } catch (err) {
    stream.emit('error', err);
  }
});

For Typescript it doesn't change anything. But for the JS built version, the error becomes catchable.

I can send a pull request if you want.

Metadata

Metadata

Labels

🚨This issue needs some love.api: datastoreIssues related to the googleapis/nodejs-datastore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions