From e0ca0e81dca6fced13ca4c31c85cdb6fb62fb221 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Mon, 1 May 2023 14:51:59 +0300 Subject: [PATCH] replace panic to std::io::Error --- src/doc.rs | 15 ++++++++++----- src/docx.rs | 15 ++++++++++----- src/odp.rs | 11 ++++++++++- src/pptx.rs | 15 ++++++++++----- src/xlsx.rs | 15 ++++++++++----- 5 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/doc.rs b/src/doc.rs index 29397aa..40abd26 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -71,11 +71,16 @@ pub(crate) fn open_doc_read_data>( } } Ok(Event::Eof) => break, - Err(e) => panic!( - "Error at position {}: {:?}", - xml_reader.buffer_position(), - e - ), + Err(e) => { + return Err(io::Error::new( + io::ErrorKind::Other, + format!( + "Error at position {}: {:?}", + xml_reader.buffer_position(), + e + ), + )) + } _ => (), } } diff --git a/src/docx.rs b/src/docx.rs index ef86f8a..294e7ce 100644 --- a/src/docx.rs +++ b/src/docx.rs @@ -67,11 +67,16 @@ impl MsDoc for Docx { } } Ok(Event::Eof) => break, // exits the loop when reaching end of file - Err(e) => panic!( - "Error at position {}: {:?}", - xml_reader.buffer_position(), - e - ), + Err(e) => { + return Err(io::Error::new( + io::ErrorKind::Other, + format!( + "Error at position {}: {:?}", + xml_reader.buffer_position(), + e + ), + )) + } _ => (), } } diff --git a/src/odp.rs b/src/odp.rs index f5304bf..989f425 100644 --- a/src/odp.rs +++ b/src/odp.rs @@ -74,7 +74,16 @@ impl OpenOfficeDoc for Odp { // } // }, // Ok(Event::Eof) => break, - // Err(e) => panic!("Error at position {}: {:?}", xml_reader.buffer_position(), e), + // Err(e) => { + // return Err(io::Error::new( + // io::ErrorKind::Other, + // format!( + // "Error at position {}: {:?}", + // xml_reader.buffer_position(), + // e + // ), + // )) + // } // _ => (), // } // } diff --git a/src/pptx.rs b/src/pptx.rs index fda6bea..3935d75 100644 --- a/src/pptx.rs +++ b/src/pptx.rs @@ -70,11 +70,16 @@ impl MsDoc for Pptx { } } Ok(Event::Eof) => break, // exits the loop when reaching end of file - Err(e) => panic!( - "Error at position {}: {:?}", - xml_reader.buffer_position(), - e - ), + Err(e) => { + return Err(io::Error::new( + io::ErrorKind::Other, + format!( + "Error at position {}: {:?}", + xml_reader.buffer_position(), + e + ), + )) + } _ => (), } } diff --git a/src/xlsx.rs b/src/xlsx.rs index dad6019..a8c1938 100644 --- a/src/xlsx.rs +++ b/src/xlsx.rs @@ -75,11 +75,16 @@ impl MsDoc for Xlsx { } } Ok(Event::Eof) => break, // exits the loop when reaching end of file - Err(e) => panic!( - "Error at position {}: {:?}", - xml_reader.buffer_position(), - e - ), + Err(e) => { + return Err(io::Error::new( + io::ErrorKind::Other, + format!( + "Error at position {}: {:?}", + xml_reader.buffer_position(), + e + ), + )) + } _ => (), } }