Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Improve error message on scan error
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 29, 2022
1 parent 37bd40a commit d237020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/de.rs
Expand Up @@ -101,17 +101,20 @@ impl<'de> Deserializer<'de> {
let mut pos = 0;
let mut jumpcount = 0;

match &self.progress {
match self.progress {
Progress::Iterable(_) => return Err(error::new(ErrorImpl::MoreThanOneDocument)),
Progress::Document(document) => {
let t = f(&mut DeserializerFromEvents {
document,
document: &document,
pos: &mut pos,
jumpcount: &mut jumpcount,
path: Path::Root,
remaining_depth: 128,
current_enum: None,
})?;
if let Some(parse_error) = document.error {
return Err(error::shared(parse_error));
}
return Ok(t);
}
_ => {}
Expand All @@ -130,6 +133,9 @@ impl<'de> Deserializer<'de> {
remaining_depth: 128,
current_enum: None,
})?;
if let Some(parse_error) = document.error {
return Err(error::shared(parse_error));
}
if loader.next_document().is_none() {
Ok(t)
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_error.rs
Expand Up @@ -18,7 +18,7 @@ where
#[test]
fn test_scan_error() {
let yaml = ">\n@";
let expected = "deserializing from YAML containing more than one document is not supported";
let expected = "found character that cannot start any token at line 2 column 1, while scanning for the next token";
test_error::<Value>(yaml, expected);
}

Expand Down

0 comments on commit d237020

Please sign in to comment.