History

fix(object): Report remaining input on error

Fixes #1099

Ed Page committed 3 years ago

Commit 55729a51 parent 58252504 files · +14 −11Browse files

Unified · Split

4 files
  1. gix-object/src/lib.rs +6 −1
  2. gix-object/tests/commit/mod.rs +1 −1
  3. gix-object/tests/tag/mod.rs +1 −1
  4. gix-object/tests/tree/mod.rs +6 −8
gix-object/src/lib.rs+6−1
@@ -291,7 +291,12 @@ pub mod decode { · 290 unmodified lines
291 291
292 impl std::fmt::Display for Error {292 impl std::fmt::Display for Error {
293 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {293 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
294 self.inner.fmt(f)294 write!(f, "object parsing failed at `{}`", bstr::BStr::new(&self.remaining))?;
295 if self.inner.context().next().is_some() {
296 writeln!(f)?;
297 self.inner.fmt(f)?;
298 }
299 Ok(())
295 }300 }
296 }301 }
297 302
gix-object/tests/commit/mod.rs+1−1
@@ -169,7 +169,7 @@ fn invalid() { · 168 unmodified lines
169 assert_eq!(169 assert_eq!(
170 CommitRef::from_bytes(partial_commit).unwrap_err().to_string(),170 CommitRef::from_bytes(partial_commit).unwrap_err().to_string(),
171 if cfg!(feature = "verbose-object-parsing-errors") {171 if cfg!(feature = "verbose-object-parsing-errors") {
172 "expected `<timestamp>`, `<name> <<email>> <timestamp> <+|-><HHMM>`, `author <signature>`"172 "object parsing failed at `1`\nexpected `<timestamp>`, `<name> <<email>> <timestamp> <+|-><HHMM>`, `author <signature>`"
173 } else {173 } else {
174 "object parsing failed"174 "object parsing failed"
175 }175 }
gix-object/tests/tag/mod.rs+1−1
@@ -123,7 +123,7 @@ fn invalid() { · 122 unmodified lines
123 assert_eq!(123 assert_eq!(
124 TagRef::from_bytes(partial_tag).unwrap_err().to_string(),124 TagRef::from_bytes(partial_tag).unwrap_err().to_string(),
125 if cfg!(feature = "verbose-object-parsing-errors") {125 if cfg!(feature = "verbose-object-parsing-errors") {
126 ""126 "object parsing failed at `tagger Sebasti`"
127 } else {127 } else {
128 "object parsing failed"128 "object parsing failed"
129 }129 }
gix-object/tests/tree/mod.rs+6−8
@@ -111,14 +111,12 @@ mod from_bytes { · 110 unmodified lines
111 fn invalid() {111 fn invalid() {
112 let fixture = fixture_name("tree", "definitely-special.tree");112 let fixture = fixture_name("tree", "definitely-special.tree");
113 let partial_tree = &fixture[..fixture.len() / 2];113 let partial_tree = &fixture[..fixture.len() / 2];
114 assert_eq!(114 let err = TreeRef::from_bytes(partial_tree).unwrap_err().to_string();
115 TreeRef::from_bytes(partial_tree).unwrap_err().to_string(),115 if cfg!(feature = "verbose-object-parsing-errors") {
116 if cfg!(feature = "verbose-object-parsing-errors") {116 assert!(err.starts_with("object parsing failed at `100644"), "{err}");
117 ""117 } else {
118 } else {118 assert_eq!(err, "object parsing failed");
119 "object parsing failed"119 }
120 }
121 );
122 assert_eq!(120 assert_eq!(
123 TreeRefIter::from_bytes(partial_tree).take_while(Result::is_ok).count(),121 TreeRefIter::from_bytes(partial_tree).take_while(Result::is_ok).count(),
124 9,122 9,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t