From de9977e571bd26fdd23ebed0773f8333708eb2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Tue, 7 Nov 2017 01:13:02 +0100 Subject: [PATCH] Don't panic in Drop. The same behavior exists (without logging) in BufWriter from std crate. It's not recommended to depend on flush during drop. Instead user should flush explicitly and check for error. --- src/file.rs | 5 ++++- src/utils.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/file.rs b/src/file.rs index 0ad246c..8326d13 100644 --- a/src/file.rs +++ b/src/file.rs @@ -138,7 +138,10 @@ impl <'a, 'b> File<'a, 'b> { impl<'a, 'b> Drop for File<'a, 'b> { fn drop(&mut self) { - self.flush().expect("flush failed"); + match self.flush() { + Err(err) => error!("flush failed {}", err), + _ => {}, + } } } diff --git a/src/utils.rs b/src/utils.rs index 3c4d107..7e56902 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -130,6 +130,9 @@ impl Seek for BufStream { impl Drop for BufStream { fn drop(&mut self) { - self.flush().expect("flush failed!"); + match self.flush() { + Err(err) => error!("flush failed {}", err), + _ => {}, + } } }