kue icon indicating copy to clipboard operation
kue copied to clipboard

Calling kue.Job.get() with undefined or null causes uncaught exception

Open niklassletteland opened this issue 10 years ago • 1 comments

Calling kue.Job.get() and passing an undefined or null id causes an uncaught exception:

FATAL: UncaughtException: Cannot read property 'toString' of undefined TypeError: Cannot read property 'toString' of undefined
   at Redis.client.createFIFO (/app/node_modules/kue/lib/redis.js:82:26)
   at Function.exports.get (/app/node_modules/kue/lib/queue/job.js:173:20)

from this entry point: https://github.com/Automattic/kue/blob/master/lib/queue/job.js#L161

the get() function does job.zid = client.createFIFO(id);.

The uncaught exception happens on this line in createFIFO(): (https://github.com/Automattic/kue/blame/master/lib/redis.js#L82)

var idLen = '' + id.toString().length;

Granted, it shouldn't be passing in undefined as id to Job.get() initially, and I can add a check to make sure that doesn't happen in my app code.

That being said, it might be better not to allow this use case to generate an uncaught exception in the Kue code, and instead call the return fn with a validation error

niklassletteland avatar Nov 21 '16 22:11 niklassletteland

submitted a proposed fix: https://github.com/Automattic/kue/pull/990

adds:

  if (id === null || id === undefined) {
    return fn(new Error('invalid "id" param in Job.get()'));
  }

check at the top of the Job.get() function to return an error instead of causing exception

niklassletteland avatar Nov 21 '16 23:11 niklassletteland