Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Ignore broken pipe in Element::print()
Merged did:key:z6MkrxqT...yQRh opened 2 months ago

I found the issue reported by spacefrogg in

https://radicle.zulipchat.com/#narrow/channel/369277-heartwood/topic/Terminal.20output.20handling.20and.20pipes/with/574695784

And figured that this might be a low-hanging fruit (at least the exact error they reported), so I went ahead and fixed it with this patch.

I am not yet sure whether this is “the way to go” for the codebase, but well, it is a proposal. Tell me what you think!

1 file changed +13 -1 7b07e57b 378365aa
modified crates/radicle-term/src/element.rs
@@ -84,8 +84,20 @@ pub trait Element: fmt::Debug + Send + Sync {

    /// Print this element to stdout.
    fn print(&self) {
+
        use std::io::Write;
+

+
        let out = std::io::stdout();
+
        let mut outlock = out.lock();
+

        for line in self.render(Constraint::from_env().unwrap_or_default()) {
-
            println!("{}", line.to_string().trim_end());
+
            if let Err(error) = writeln!(outlock, "{}", line.to_string().trim_end()) {
+
                if error.kind() == std::io::ErrorKind::BrokenPipe {
+
                    // Ignore broken pipe error and simply return
+
                    break;
+
                } else {
+
                    panic!("{error}");
+
                }
+
            }
        }
    }