LaurentZuijdwijk/streaming-cache

Review/Improve stream error handling

Closed this issue · 4 comments

Improve handling of stream errors in index.js. What sort of errors can happen there? Read errors? Write errors? Are those caused by the library or the client? Is deleting the key from cache the most sensible thing to do in all cases?

    stream.on('error', function (err) {
          console.log('stream errror')
          self.cache.del(key);

Then documentation says streams are not closed automatically if an error event happens. Is this a warning that we should close it, or just a note that at that point will still not be closed (but will be later, automatically)? Do we need to do something about this?

https://nodejs.org/api/stream.html#stream_event_error

Then documentation says streams are not closed automatically if an error event happens.

I think that is a misunderstanding, because the documentation reads

Note: The stream is not closed when the 'error' event is emitted.

which only states that 'error' handlers will always be called before 'close' handlers. This allows you to check in your 'close' handler whether an error occurred before the stream was closed.

Thank you for your reply @ustuehler. I do think that the current implementation should suffice, not store the data and let the consumer deal with the error.

Thank you for your contribution @ustuehler.