aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-09-16 22:45:52 +0200
committerTeddy Wing2020-09-16 22:45:52 +0200
commitb6002fee979606986458449b8ffe6d290dbba8d1 (patch)
tree5a59f36e485ca2ba8f4fc6334c6e03677e42d380
parent6fdf7b121bcddbc0328703f34fdb0fee71e03dc8 (diff)
downloadgit-todo-b6002fee979606986458449b8ffe6d290dbba8d1.tar.bz2
write_since(): Handle errors in `diff.foreach()` callback
* Ignore lines that don't parse to UTF-8. Might want to figure out how to support other encodings. * Ignore lines that don't have a `path`. * Panic on write errors.
-rw-r--r--src/lib.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0b64b22..4faaf20 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -41,16 +41,18 @@ impl Todos<'_> {
// );
if let Some(line_number) = line.new_lineno() {
- let l = std::str::from_utf8(line.content()).unwrap();
-
- if l.contains("TODO") {
- write!(
- write_to,
- "{}:{}:{}",
- delta.new_file().path().unwrap().display(),
- line_number,
- l,
- ).unwrap();
+ if let Ok(l) = std::str::from_utf8(line.content()) {
+ if l.contains("TODO") {
+ if let Some(path) = delta.new_file().path() {
+ write!(
+ write_to,
+ "{}:{}:{}",
+ path.display(),
+ line_number,
+ l,
+ ).expect("write error");
+ }
+ }
}
}