Unable to catch error in piped streams | Uncaught TypeError [ERR_INVALID_ARG_TYPE]
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
Version
v14.18.1
Platform
macOS Big Sur
Subsystem
No response
What steps will reproduce the bug?
When we pipe multiple streams and the data coming from the first stream is an array, then it is expected to have an error. But I am unable to catch this error in this case and it is throwing the below error.
**internal/streams/writable.js:285
throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Array
at new NodeError (internal/errors.js:322:7)
at WriteStream.Writable.write (internal/streams/writable.js:285:13)
at Stream.ondata (internal/streams/legacy.js:20:31)
at Stream.emit (events.js:400:28)
at drain (/Users/mayankkatare/Trainings/Node assignments/node_modules/through/index.js:36:16)
at Stream.stream.queue.stream.push (/Users/mayankkatare/Trainings/Node assignments/node_modules/through/index.js:45:5)
at Parser.parser.onValue (/Users/mayankkatare/Trainings/Node assignments/node_modules/JSONStream/index.js:118:16)
at Parser.proto.emit (/Users/mayankkatare/Trainings/Node assignments/node_modules/jsonparse/jsonparse.js:337:8)
at Parser.proto.pop (/Users/mayankkatare/Trainings/Node assignments/node_modules/jsonparse/jsonparse.js:332:8)
at Parser.proto.onToken (/Users/mayankkatare/Trainings/Node assignments/node_modules/jsonparse/jsonparse.js:402:12) {
code: 'ERR_INVALID_ARG_TYPE'
}**
------Repro script--------
const request = require('request');
const JSONStream = require('JSONStream')
const fs = require('fs')
let Url = 'http://localhost:5000/' // This url returns a response
request(Url).on('response', respHandler)
function respHandler(res) {
let jsonStream = JSONStream.parse(['data']) // Assuming response is {data:['Home page', 'Jackson']}
var file = fs.createWriteStream('someNewFile.txt')
try {
// Trying to catch error on each stream initially
res.on('error', err => console.log(err));
jsonStream.on('error', err => console.log(err));
file.on('error', err => console.log(err));
// Trying to catch error during piping
res.pipe(jsonStream).on('error', (err) => {
console.log(err)
if(err) {
console.log(err);
}
}).pipe(file).on('error', (err) => {
console.log(err)
if(err) {
console.log(err);
}
})
} catch (error) {
if(error)
console.log(error);
}
}
How often does it reproduce? Is there a required condition?
Everytime
What is the expected behavior?
It should throw an error but we should be able to handle this error so that our app should not crash. We should be able to catch the error in error event handler. This was the behaviour in 12.15.0 and it seems to have changed in 14.18.1
What do you see instead?
Uncaught TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Array
Additional information
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された再現手順から始め、Stream.ondata から internal/streams/writable.js までスタックを追跡します。v14.18.1 で実行し、報告された動作を v12.15.0 と比較します。特に、pipe されたストリームからのエラーが登録済みのエラーハンドラーにどのように到達するかに注目してください。無効な配列チャンクがエラーハンドラーを通じて報告され、uncaught なプロセスクラッシュが発生しなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, node.js
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100