Skip to content

fix: use nullish coalescing for job data and options defaults - #1031

Open
tsushanth wants to merge 1 commit into
bee-queue:masterfrom
tsushanth:fix/job-nullish-coalescing-options
Open

fix: use nullish coalescing for job data and options defaults#1031
tsushanth wants to merge 1 commit into
bee-queue:masterfrom
tsushanth:fix/job-nullish-coalescing-options

Conversation

@tsushanth

Copy link
Copy Markdown

What

Job constructor uses || to supply defaults for data, options, options.timestamp, and options.stacktraces. This silently replaces any falsy-but-valid value with the default:

this.data = data || {};           // data=false → {}; data=0 → {}; data='' → {}
this.options = options || {};
this.options.timestamp = this.options.timestamp || Date.now();  // timestamp=0 → Date.now()
this.options.stacktraces = this.options.stacktraces || [];

A queue consumer that stores boolean flags, numeric codes, or empty strings as job data loses the payload silently.

Fix

Replace || with ?? so only null and undefined fall through to the default:

this.data = data ?? {};
this.options = options ?? {};
this.options.timestamp = this.options.timestamp ?? Date.now();
this.options.stacktraces = this.options.stacktraces ?? [];

Reproduction

const job = queue.createJob(false);
await job.save();
// job.data is {} instead of false

Replace || with ?? when initializing data, options, timestamp, and
stacktraces so that falsy-but-valid values (false, 0, empty string) are
not silently replaced with the default. A job created with numeric or
boolean data was losing its payload.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants