ndjson-cli icon indicating copy to clipboard operation
ndjson-cli copied to clipboard

Error output may be truncated before the error message

Open robinhouston opened this issue 7 years ago • 0 comments

Many of the ndjson tools use error reporting code of the following sort – this example is from ndjson-split:

  try {
    sandbox.d = JSON.parse(line);
  } catch (error) {
    console.error("stdin:" + (i + 1));
    console.error(line);
    console.error("^");
    console.error("SyntaxError: " + error.message);
    process.exit(1);
  }

When processing something like GeoJSON, line may contain a substantial amount of data. In that case the process will exit before the output buffer has been fully printed, with the effect that the error output is truncated before the actual error message has been printed.

The documentation for process.exit warns that this can happen:

It is important to note that calling process.exit() will force the process to exit as quickly as possible even if there are still asynchronous operations pending that have not yet completed fully, including I/O operations to process.stdout and process.stderr.

Obviously not printing the error message makes debugging more difficult.

robinhouston avatar Jul 19 '17 19:07 robinhouston