Fixes #1099
Unified · Split
| @@ -291,7 +291,12 @@ pub mod decode { · 290 unmodified lines | ||
| 291 | 291 | |
| 292 | 292 | impl std::fmt::Display for Error { |
| 293 | 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 | |
| @@ -169,7 +169,7 @@ fn invalid() { · 168 unmodified lines | ||
| 169 | 169 | assert_eq!( |
| 170 | 170 | CommitRef::from_bytes(partial_commit).unwrap_err().to_string(), |
| 171 | 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 | 173 | } else { |
| 174 | 174 | "object parsing failed" |
| 175 | 175 | } |
| @@ -123,7 +123,7 @@ fn invalid() { · 122 unmodified lines | ||
| 123 | 123 | assert_eq!( |
| 124 | 124 | TagRef::from_bytes(partial_tag).unwrap_err().to_string(), |
| 125 | 125 | if cfg!(feature = "verbose-object-parsing-errors") { |
| 126 | − "" | |
| 126 | + "object parsing failed at `tagger Sebasti`" | |
| 127 | 127 | } else { |
| 128 | 128 | "object parsing failed" |
| 129 | 129 | } |
| @@ -111,14 +111,12 @@ mod from_bytes { · 110 unmodified lines | ||
| 111 | 111 | fn invalid() { |
| 112 | 112 | let fixture = fixture_name("tree", "definitely-special.tree"); |
| 113 | 113 | let partial_tree = &fixture[..fixture.len() / 2]; |
| 114 | − assert_eq!( | |
| 115 | − TreeRef::from_bytes(partial_tree).unwrap_err().to_string(), | |
| 116 | − if cfg!(feature = "verbose-object-parsing-errors") { | |
| 117 | − "" | |
| 118 | − } else { | |
| 119 | − "object parsing failed" | |
| 120 | − } | |
| 121 | − ); | |
| 114 | + let err = TreeRef::from_bytes(partial_tree).unwrap_err().to_string(); | |
| 115 | + if cfg!(feature = "verbose-object-parsing-errors") { | |
| 116 | + assert!(err.starts_with("object parsing failed at `100644"), "{err}"); | |
| 117 | + } else { | |
| 118 | + assert_eq!(err, "object parsing failed"); | |
| 119 | + } | |
| 122 | 120 | assert_eq!( |
| 123 | 121 | TreeRefIter::from_bytes(partial_tree).take_while(Result::is_ok).count(), |
| 124 | 122 | 9, |