Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: stream.pipeline documentation is misleading WRT 'Iterable' as a valid first argument. #36437

Closed
1 task
rbuckton opened this issue Dec 8, 2020 · 1 comment
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.

Comments

@rbuckton
Copy link

rbuckton commented Dec 8, 2020

📗 API Reference Docs Problem

  • Version: v14.7.0
  • Platform: Windows 10 (64-bit)
  • Subsystem: stream

Location

Affected URL(s):

Description

The documentation states the following:

image

This is misleading, as an Array is a valid Iterable, yet using an Array as the first argument with multiple streams results in an error:

const stream = require("stream");

async function main() {
    await stream.pipeline(
        /*stream1*/ [1, 2, 3],
        /*stream2*/ new stream.PassThrough({ objectMode: true }),
        /*callback*/ () => { console.log("done"); });
}

main().catch(e => console.error(e));

Output:

TypeError [ERR_INVALID_ARG_TYPE]: The "source" argument must be of type function or an instance of Stream, Iterable, or AsyncIterable. Received type number (1)
    at Function.pipeline (internal/streams/pipeline.js:199:15)
    at main (D:\dev\scratch\pipeline\index.js:4:18)
    at Object.<anonymous> (D:\dev\scratch\pipeline\index.js:10:1)
    at Module._compile (internal/modules/cjs/loader.js:1256:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1277:10)
    at Module.load (internal/modules/cjs/loader.js:1105:32)
    at Function.Module._load (internal/modules/cjs/loader.js:967:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_ARG_TYPE'
}

However, if you change [1, 2, 3] to [1, 2, 3].values() then the call evaluates successfully. It seems like stream.pipeline sees the first argument is an Array and always picks stream.pipeline(streams, callback), even if there is a destination and may be one or more transforms.

The way the parameters are represented is also confusing. It looks like they are sorted alphabetically rather than based on the "overload" being called, so the "Returns:" bullet points don't make much sense.


  • I would like to work on this issue and submit a pull request.
@ronag
Copy link
Member

ronag commented Dec 9, 2020

sounds like a bug in pipeline

@ronag ronag added stream Issues and PRs related to the stream subsystem. good first issue Issues that are suitable for first-time contributors. labels Dec 9, 2020
Lxxyx added a commit to Lxxyx/node that referenced this issue Dec 11, 2020
targos pushed a commit that referenced this issue Dec 21, 2020
Fixes: #36437

PR-URL: #36479
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
BethGriggs pushed a commit that referenced this issue Jan 19, 2021
Fixes: #36437

PR-URL: #36479
Backport-PR-URL: #36831
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
BethGriggs pushed a commit that referenced this issue Jan 28, 2021
Fixes: #36437

PR-URL: #36479
Backport-PR-URL: #36831
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants