Calling queue constructor w/o a name causes a background promise rejection
Created by: osher
Description
Minimal, Working Test code to reproduce the issue.
(An easy to reproduce test case will dramatically decrease the resolution time.)
code:
const Q = require('bull');
const r = new Q(); //<-------- not provided a name
r.add('stam', {foo: 'bar'}).then(v => console.log('added', v));
Expected
should either work with no problems, or throw an assertion early on during queue creation.
Found
(node:24088) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
at Function.from (buffer.js:331:9)
at Queue.base64Name (c:\generator\node_modules\bull\lib\worker.js:38:19)
at Queue.clientName (c:\generator\node_modules\bull\lib\worker.js:42:40)
at c:\generator\node_modules\bull\lib\worker.js:16:51
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:24088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:24088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
There is nothing that I as a user can do to prevent this background promise rejection from happening, except for providing a name.
So what I would consider professional is that either the constructor should throw upon missing name, or there should be a baked-in default.
more info
I'm doing it in a node shell as part of my evaluation
c:\osher\eval-bull>node
Welcome to Node.js v12.18.4.
Type ".help" for more information.
> Q = require('bull'); r = new Q(); emit = r.emit; r.emit = (...a) => console.log(a) || emit.apply(r, a);1
1
> r.add('stam', {foo: 'bar'}).then(v => console.log('added', v));1
1
> added Job {
opts: {
jobId: undefined,
attempts: 1,
delay: 0,
timestamp: 1610955263079,
backoff: undefined
},
name: 'stam',
...
... skip a few lines ...
...
id: '3'
}
> r.process('stam', (j, done) => console.log('stam job', j.data) || done(null));1
1
> (node:24088) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
at Function.from (buffer.js:331:9)
at Queue.base64Name (c:\generator\node_modules\bull\lib\worker.js:38:19)
at Queue.clientName (c:\generator\node_modules\bull\lib\worker.js:42:40)
at c:\generator\node_modules\bull\lib\worker.js:16:51
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:24088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:24088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[ 'registered:delayed' ]
stam job { foo: 'bar' }
[
'active',
Job { ...
Bull version
bull@3.20.0
Additional information
All the info was in the original reports:
#1956
#1958 (closed)