nodejs / nodejs/node

stream: handling invalid stream arguments in `stream.pipeline()`

未关闭
#55,305 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

never-stale stream
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

A few "what goes where"-related inconsistencies with stream.pipeline(). Validation of stream objects is very hit-and-miss:

Passing this: as this: should do this: and does this:
Non-readable Node stream source Should be rejected. :x: Passes validation. Gets passed to Duplex.from(), resulting in a write-only Duplex. The pipeline will never receive any data.
transform Should be rejected. :heavy_check_mark: Fails validation.
destination Should be accepted. :heavy_check_mark: Passes validation.
Non-writable Node stream source Should be accepted. :heavy_check_mark: Passes validation.
transform Should be rejected. :x: Passes validation. Fails asynchronously at runtime: when the previous stream in the pipeline emits data, raises a TypeError due to attempting to call missing Writable methods.
destination Should be rejected. :x: Same as above.
ReadableStream source Should be accepted. :heavy_check_mark: Passes validation.
transform Should be rejected. :heavy_check_mark: Fails validation.
destination Should be rejected. :x: Passes validation. Fails asynchronously at runtime: raises a TypeError due to attempting to call the missing getWriter() method.
TransformStream source Undocumented, but should be accepted. :heavy_check_mark: Passes validation.
transform Should be accepted. :heavy_check_mark: Passes validation.
destination Undocumented, but should be accepted. :heavy_check_mark: Passes validation.
WritableStream source Should be rejected. :x: Passes validation. Gets passed to Duplex.from(), resulting in a write-only Duplex. The pipeline will never receive any data.
transform Should be rejected. :heavy_check_mark: Fails validation.
destination Should be accepted. :heavy_check_mark: Passes validation.

These should probably be validated consistently.

Other observations:

  • The docs should specify that TransformStreams are valid source and destination streams, as well as valid return values.
  • The transform validation error message doesn't specify which parameter failed validation, which is a pain in terms of debugging. Its counterparts in stream.compose() pass the parameter name to the error constructor as streams[n], which would be a fairly straightforward improvement.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 lib/internal/streams/pipeline.js 中链接的验证路径开始,尤其检查第 306-308、376 以及 391-395 行附近对 source、transform 和 destination 的处理。比较 stream.compose() 使用的参数命名,并查看相关的 stream 文档。完成的标准是:无效参数被一致地拒绝,验证错误指出失败的参数,并且按照描述记录对 TransformStream 的支持。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
backend, documentation
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。