mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 02:12:22 +00:00
Exit gracefully on broken pipe errors (#13485)
## Summary Closes https://github.com/astral-sh/ruff/issues/13483. Closes https://github.com/astral-sh/ruff/issues/13442. ## Test Plan ``` ❯ cargo run analyze graph ../django | head -n 10 Compiling ruff v0.6.7 (/Users/crmarsh/workspace/ruff/crates/ruff) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s Running `target/debug/ruff analyze graph ../django` warning: `ruff analyze graph` is experimental and may change without warning { "/Users/crmarsh/workspace/django/django/__init__.py": [ "/Users/crmarsh/workspace/django/django/apps/__init__.py", "/Users/crmarsh/workspace/django/django/conf/__init__.py", "/Users/crmarsh/workspace/django/django/urls/__init__.py", "/Users/crmarsh/workspace/django/django/utils/log.py", "/Users/crmarsh/workspace/django/django/utils/version.py" ], "/Users/crmarsh/workspace/django/django/__main__.py": [ "/Users/crmarsh/workspace/django/django/core/management/__init__.py" ```
This commit is contained in:
parent
90dc7438ee
commit
96e7f3f96f
1 changed files with 11 additions and 1 deletions
|
@ -3,6 +3,7 @@ use std::process::ExitCode;
|
|||
use clap::{Parser, Subcommand};
|
||||
use colored::Colorize;
|
||||
use log::error;
|
||||
use std::io::Write;
|
||||
|
||||
use ruff::args::{Args, Command};
|
||||
use ruff::{run, ExitStatus};
|
||||
|
@ -86,7 +87,16 @@ pub fn main() -> ExitCode {
|
|||
Ok(code) => code.into(),
|
||||
Err(err) => {
|
||||
{
|
||||
use std::io::Write;
|
||||
// Exit "gracefully" on broken pipe errors.
|
||||
//
|
||||
// See: https://github.com/BurntSushi/ripgrep/blob/bf63fe8f258afc09bae6caa48f0ae35eaf115005/crates/core/main.rs#L47C1-L61C14
|
||||
for cause in err.chain() {
|
||||
if let Some(ioerr) = cause.downcast_ref::<std::io::Error>() {
|
||||
if ioerr.kind() == std::io::ErrorKind::BrokenPipe {
|
||||
return ExitCode::from(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use `writeln` instead of `eprintln` to avoid panicking when the stderr pipe is broken.
|
||||
let mut stderr = std::io::stderr().lock();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue