使用 node.js 流进行错误处理 - Error handling with node.js streams

问题:

What's the correct way to handle errors with streams?处理流错误的正确方法是什么? I already know there's an 'error' event you can listen on, but I want to know some more details about arbitrarily complicated situations.我已经知道有一个“错误”事件可以收听,但我想了解有关任意复杂情况的更多详细信息。

For starters, what do you do when you want to do a simple pipe chain:首先,当你想做一个简单的管道链时,你会怎么做:

input.pipe(transformA).pipe(transformB).pipe(transformC)...

And how do you properly create one of those transforms so that errors are handled correctly?您如何正确创建这些转换之一以便正确处理错误?

More related questions:更多相关问题:

  • when an error happens, what happens to the 'end' event?发生错误时,“结束”事件会发生什么? Does it never get fired?它永远不会被解雇吗? Does it sometimes get fired?它有时会被解雇吗? Does it depend on the transform/stream?它取决于转换/流吗? What are the standards here?这里的标准是什么?
  • are there any mechanisms for propogating errors through the pipes?是否有通过管道传播错误的机制?
  • do domains solve this problem effectively?域能有效地解决这个问题吗? Examples would be nice.例子会很好。
  • do errors that come out of 'error' events have stack traces?来自“错误”事件的错误是否有堆栈跟踪? Sometimes?有时? Never?绝不? is there a way to get one from them?有没有办法从他们那里得到一个?

解决方案:

参考一: https://en.stackoom.com/question/1TLgi
参考二: https://stackoom.com/question/1TLgi
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章