Unable to catch error in piped streams | Uncaught TypeError [ERR_INVALID_ARG_TYPE]
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 122k
- Forks
- 37.3k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 283
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comience con la reproducción proporcionada y siga el stack desde Stream.ondata hasta internal/streams/writable.js. Ejecútela con v14.18.1 y compare el comportamiento observado con v12.15.0, centrándose en cómo los errores de los streams canalizados llegan a los controladores de errores registrados. Se considera que está terminado cuando el chunk de array no válido se notifica mediante un controlador de errores sin provocar un bloqueo no controlado del proceso.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, node.js
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100