Eliminate panics and enable the missing panics docs check

This commit is contained in:
David Aguilar 2024-03-17 02:56:21 -07:00 committed by Ethiraric
parent a42f26b306
commit 9e505d552f
4 changed files with 18 additions and 8 deletions

View file

@ -16,6 +16,8 @@
- `Yaml::load_from_bytes()` is now available. - `Yaml::load_from_bytes()` is now available.
([#156](https://github.com/chyh1990/yaml-rust/pull/156)) ([#156](https://github.com/chyh1990/yaml-rust/pull/156))
- The parser and scanner now return Err() instead of calling panic.
**Development**: **Development**:
- The documentation was updated to include a security note mentioning that - The documentation was updated to include a security note mentioning that

View file

@ -33,11 +33,7 @@
#![cfg_attr(feature = "cargo-clippy", warn(clippy::pedantic))] #![cfg_attr(feature = "cargo-clippy", warn(clippy::pedantic))]
#![cfg_attr( #![cfg_attr(
feature = "cargo-clippy", feature = "cargo-clippy",
allow( allow(clippy::should_implement_trait, clippy::missing_errors_doc,)
clippy::should_implement_trait,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
)
)] )]
extern crate hashlink; extern crate hashlink;

View file

@ -306,7 +306,9 @@ impl<T: Iterator<Item = char>> Parser<T> {
) -> Result<(), ScanError> { ) -> Result<(), ScanError> {
if !self.scanner.stream_started() { if !self.scanner.stream_started() {
let (ev, mark) = self.next()?; let (ev, mark) = self.next()?;
assert_eq!(ev, Event::StreamStart); if ev != Event::StreamStart {
return Err(ScanError::new(mark, "did not find expected <stream-start>"));
}
recv.on_event(ev, mark); recv.on_event(ev, mark);
} }
@ -337,7 +339,12 @@ impl<T: Iterator<Item = char>> Parser<T> {
mark: Marker, mark: Marker,
recv: &mut R, recv: &mut R,
) -> Result<(), ScanError> { ) -> Result<(), ScanError> {
assert_eq!(first_ev, Event::DocumentStart); if first_ev != Event::DocumentStart {
return Err(ScanError::new(
mark,
"did not find expected <document-start>",
));
}
recv.on_event(first_ev, mark); recv.on_event(first_ev, mark);
let (ev, mark) = self.next()?; let (ev, mark) = self.next()?;

View file

@ -716,7 +716,12 @@ impl<T: Iterator<Item = char>> Scanner<T> {
if !self.token_available { if !self.token_available {
self.fetch_more_tokens()?; self.fetch_more_tokens()?;
} }
let t = self.tokens.pop_front().unwrap(); let Some(t) = self.tokens.pop_front() else {
return Err(ScanError::new(
self.mark,
"did not find expected next token",
));
};
self.token_available = false; self.token_available = false;
self.tokens_parsed += 1; self.tokens_parsed += 1;