Skip to content

duplexify must be in object mode for mod streams#95

Merged
1 commit merged into
cabal-club:masterfrom
garbados:patch-2
Jun 25, 2020
Merged

duplexify must be in object mode for mod streams#95
1 commit merged into
cabal-club:masterfrom
garbados:patch-2

Conversation

@garbados

@garbados garbados commented Jun 25, 2020

Copy link
Copy Markdown
Contributor

This is a WIP PR because I am unfamiliar with the testing suite, so it only fixes my problem presently.

The issue is that if you treat cabal.moderation.list as a read stream instead of utilizing its callback, you get this:

Uncaught TypeError: The "chunk" argument must be one of type string, Buffer, or Uint8Array. Received type object
      at chunkInvalid (node_modules/readable-stream/lib/_stream_readable.js:313:10)
      at readableAddChunk (node_modules/readable-stream/lib/_stream_readable.js:258:31)
      at Duplexify.Readable.push (node_modules/readable-stream/lib/_stream_readable.js:241:10)
      at Duplexify._forward (node_modules/duplexify/index.js:172:26)
      at Readable.onreadable (node_modules/duplexify/index.js:136:10)
      at emitReadable_ (node_modules/read-only-stream/node_modules/readable-stream/lib/_stream_readable.js:504:10)
      at emitReadable (node_modules/read-only-stream/node_modules/readable-stream/lib/_stream_readable.js:498:62)
      at addChunk (node_modules/read-only-stream/node_modules/readable-stream/lib/_stream_readable.js:298:29)
      at readableAddChunk (node_modules/read-only-stream/node_modules/readable-stream/lib/_stream_readable.js:278:11)
      at Readable.push (node_modules/read-only-stream/node_modules/readable-stream/lib/_stream_readable.js:245:10)
      at Readable.ro._read (node_modules/read-only-stream/index.js:22:16)
      at DestroyableTransform.<anonymous> (node_modules/read-only-stream/index.js:15:16)
      at emitReadable_ (node_modules/readable-stream/lib/_stream_readable.js:538:12)
      at processTicksAndRejections (internal/process/task_queues.js:83:21)

Here's an excerpt from the source that triggers the issue:

const modStream = cabal.moderation.list()
modStream.on('data', (action) => {
  console.log(action)
})

The problem is, apparently, that duplexify must be in object mode to handle the objects produced by the stream. This is accomplished by changing duplexify() into duplexify.obj()

@garbados

Copy link
Copy Markdown
Contributor Author

PR updated to include a test.

@ghost ghost merged commit 9ab9c74 into cabal-club:master Jun 25, 2020
@ghost

ghost commented Jun 25, 2020

Copy link
Copy Markdown

Thanks for the patch! This has been merged into 13.0.2.

This pull request was closed.
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.

1 participant