mcollina / fastq

Fast, in memory work queue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Q: Error handler is not suppressing the error

mccare opened this issue · comments

My impression of error handler was, that it would handle the error and not pass it on. The error handler is called also every time (with error == null).

  • I would expect error only being called on error
  • and I would expect that the error handler would suppress the error reporting up the chain

Am I setting up the queue wrong or should I write a worker wrapper for suppressing/handling the error? Thanks for some insight, looking forward to the "broken promise" talk! Head is spinning :-)

var queue = require("fastq").promise(worker, 1);

queue.error(function (err, task) {
  console.log("Error is ", err);
  console.log("Task is ", task);
});

async function worker(arg) {
  if (arg == 84) {
    throw new Error("just an error");
  }
  return arg * 2;
}

async function run() {
  const result = await queue.push(42);
  console.log("the result is", result);
  const result2 = await queue.push(84);
  console.log("the result is", result2);
}

run();

I guess this is by design, since the tests also test for this behaviour.

Yes exactly.

The docs however do not reflect this:

Set a global error handler. handler(err, task) will be called when any of the tasks return an error.

fastq/README.md

Lines 225 to 228 in 3b9f23d

### queue.error(handler)
Set a global error handler. `handler(err, task)` will be called
when any of the tasks return an error.

Same situation here. I think that the documentation should be updated to reflect this behaviour...