mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-22 02:50:39 +08:00
Prevent `rad` from panicking when its stdout is a closed pipe, e.g. when running `rad config | head`. The broken pipes are handled at the output boundaries using three layers of defence: 1. Inner: Route all stdout output through `term::print()` and `term::print_inline()`, which use explicit `writeln!`/`write!` to a locked stdout and silently ignore write errors. All `println!` calls in `radicle-cli` and `radicle-term` are converted. 2. Middle: Catch `BrokenPipe` errors that propagate up via `anyhow` from subcommands in `main::run()`, and exit cleanly with code 0. 3. Outer: Install a panic hook that intercepts `println!` panics containing "Broken pipe" (from dependencies like clap) and exits cleanly, chained in front of human_panic's hook. To prevent regressions, `#![deny(clippy::print_stdout)]` is added to `radicle-cli`, requiring all future stdout output to go through the safe `term::` functions. Note: `eprintln!` calls (stderr) are not handled, as broken stderr pipes are extremely rare in practice.
16 lines
377 B
Rust
16 lines
377 B
Rust
#![allow(clippy::too_many_arguments)]
|
|
// Prevent use of `println!` and `print!` which panic on broken pipes.
|
|
// Use `terminal::io::println` or `terminal::io::print` instead.
|
|
#![deny(clippy::print_stdout)]
|
|
pub mod commands;
|
|
pub mod git;
|
|
pub mod node;
|
|
pub mod pager;
|
|
pub mod project;
|
|
pub mod terminal;
|
|
|
|
mod common_args;
|
|
mod warning;
|
|
|
|
extern crate radicle_localtime as localtime;
|