chiark / gitweb /
utils: error end_process: Do not print duplicate messages
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 1 Jun 2021 00:26:15 +0000 (01:26 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 1 Jun 2021 00:33:18 +0000 (01:33 +0100)
Sometimes we use thiserror to put {0} of an inner error in our Display
impl.  If that happens, just skip the repetition.

This is a slight bodge.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/utils.rs

index 0daef6369fe8f2693ad405125668f7ffb1a1b369..9c73675a6f5dac3ec2f883c5a5c0920a211324e2 100644 (file)
@@ -659,13 +659,16 @@ impl anyhow::Error {
       }
     }
     let mut sol: Sol = default();
+    let mut printed = String::new();
     for e in self.chain() {
       let s = e.to_string();
+      if printed.contains(&s) { continue }
       let long = s.len() > 80;
       if long && sol.any { sol.nl() }
       sol.head();
-      eprint!(": {}", s);
+      eprint!(": {}", &s);
       if long { sol.nl() }
+      printed = s;
     }
     sol.nl();
     assert!(estatus > 0);