Improved stream error handling