scramjetorg / scramjet

Public tracker for Scramjet Cloud Platform, a platform that bring data from many environments together.
https://www.scramjet.org
MIT License
253 stars 20 forks source link

DataStream.toJSONArray causes an exception on empty input #106

Closed nabriski closed 3 years ago

nabriski commented 3 years ago

Describe the bug When calling toJSONArray on an empty stream, an exception is thrown. I tried it both with an empty array and with a mongo db cursor for a query returning no records.

To Reproduce

DataStream
  .from([])
  .toJSONArray()
  .pipe(process.stdout)

Causes:

(node:58686) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toString' of undefined
    at StringStream._transform (/private/tmp/node_modules/scramjet-core/lib/string-stream.js:248:25)
    at StringStream.Transform._read (_stream_transform.js:205:10)
    at StringStream.Transform._write (_stream_transform.js:193:12)
    at writeOrBuffer (_stream_writable.js:352:12)
    at StringStream.Writable.write (_stream_writable.js:303:10)
    at StringStream.whenWrote (/private/tmp/node_modules/scramjet-core/lib/util/promise-transform-stream.js:186:24)
    at /private/tmp/node_modules/scramjet/lib/data-stream.js:1020:65
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:58686) 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: 8)

Expected behavior The string "[]" should be outputted to stdout

System:

Thanks, Itamar

MichalCz commented 3 years ago

Thanks for reporting this. I'll look into this during the weekend.

M.

MichalCz commented 3 years ago

Ok, so an update - bit late, but still.

There was an issue with all tests when one timeout just stopped all subsequent tests and exited the test runner with exitCode &eq; 0.

I can confirm the issue and this should be fixed - there's a similar problem in flatMap I already solved, so this should be fairly simple.

nabriski commented 3 years ago

Thanks for the update, I have a workaround right now but I'll update to the fix once it's released.

MichalCz commented 3 years ago

No probs @nabriski. Can you confirm the fix in v4.35.17?

nabriski commented 3 years ago

confirmed, thanks!