Improve stream error handling.