Skip to content

Commit 06b1600

Browse files
authored
Merge pull request #6 from SpectralOps/remove-panics
replace panic to std::io::Error
2 parents ed8fc7b + e0ca0e8 commit 06b1600

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
lines changed

src/doc.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ pub(crate) fn open_doc_read_data<P: AsRef<Path>>(
7171
}
7272
}
7373
Ok(Event::Eof) => break,
74-
Err(e) => panic!(
75-
"Error at position {}: {:?}",
76-
xml_reader.buffer_position(),
77-
e
78-
),
74+
Err(e) => {
75+
return Err(io::Error::new(
76+
io::ErrorKind::Other,
77+
format!(
78+
"Error at position {}: {:?}",
79+
xml_reader.buffer_position(),
80+
e
81+
),
82+
))
83+
}
7984
_ => (),
8085
}
8186
}

src/docx.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ impl MsDoc<Docx> for Docx {
6767
}
6868
}
6969
Ok(Event::Eof) => break, // exits the loop when reaching end of file
70-
Err(e) => panic!(
71-
"Error at position {}: {:?}",
72-
xml_reader.buffer_position(),
73-
e
74-
),
70+
Err(e) => {
71+
return Err(io::Error::new(
72+
io::ErrorKind::Other,
73+
format!(
74+
"Error at position {}: {:?}",
75+
xml_reader.buffer_position(),
76+
e
77+
),
78+
))
79+
}
7580
_ => (),
7681
}
7782
}

src/odp.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,16 @@ impl OpenOfficeDoc<Odp> for Odp {
7474
// }
7575
// },
7676
// Ok(Event::Eof) => break,
77-
// Err(e) => panic!("Error at position {}: {:?}", xml_reader.buffer_position(), e),
77+
// Err(e) => {
78+
// return Err(io::Error::new(
79+
// io::ErrorKind::Other,
80+
// format!(
81+
// "Error at position {}: {:?}",
82+
// xml_reader.buffer_position(),
83+
// e
84+
// ),
85+
// ))
86+
// }
7887
// _ => (),
7988
// }
8089
// }

src/pptx.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ impl MsDoc<Pptx> for Pptx {
7070
}
7171
}
7272
Ok(Event::Eof) => break, // exits the loop when reaching end of file
73-
Err(e) => panic!(
74-
"Error at position {}: {:?}",
75-
xml_reader.buffer_position(),
76-
e
77-
),
73+
Err(e) => {
74+
return Err(io::Error::new(
75+
io::ErrorKind::Other,
76+
format!(
77+
"Error at position {}: {:?}",
78+
xml_reader.buffer_position(),
79+
e
80+
),
81+
))
82+
}
7883
_ => (),
7984
}
8085
}

src/xlsx.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ impl MsDoc<Xlsx> for Xlsx {
7575
}
7676
}
7777
Ok(Event::Eof) => break, // exits the loop when reaching end of file
78-
Err(e) => panic!(
79-
"Error at position {}: {:?}",
80-
xml_reader.buffer_position(),
81-
e
82-
),
78+
Err(e) => {
79+
return Err(io::Error::new(
80+
io::ErrorKind::Other,
81+
format!(
82+
"Error at position {}: {:?}",
83+
xml_reader.buffer_position(),
84+
e
85+
),
86+
))
87+
}
8388
_ => (),
8489
}
8590
}

0 commit comments

Comments
 (0)