From 68f21628064bb9f6bb9bba0375a9f6c4f221026e Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Sat, 26 Apr 2025 11:51:10 +0200 Subject: [PATCH 1/2] [red-knot] Use 'error' exit code when there's at least one diagnostic with severity 'fatal' --- crates/red_knot/src/main.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/red_knot/src/main.rs b/crates/red_knot/src/main.rs index a0e47b2d71f86..94d233781fbd1 100644 --- a/crates/red_knot/src/main.rs +++ b/crates/red_knot/src/main.rs @@ -269,12 +269,6 @@ impl MainLoop { .format(terminal_settings.output_format) .color(colored::control::SHOULD_COLORIZE.should_colorize()); - let min_error_severity = if terminal_settings.error_on_warning { - Severity::Warning - } else { - Severity::Error - }; - if check_revision == revision { if db.project().files(db).is_empty() { tracing::warn!("No python files found under the given path(s)"); @@ -289,13 +283,13 @@ impl MainLoop { return Ok(ExitStatus::Success); } } else { - let mut failed = false; + let mut max_severity = Severity::Info; let diagnostics_count = result.len(); for diagnostic in result { write!(stdout, "{}", diagnostic.display(db, &display_config))?; - failed |= diagnostic.severity() >= min_error_severity; + max_severity = max_severity.max(diagnostic.severity()); } writeln!( @@ -306,10 +300,17 @@ impl MainLoop { )?; if self.watcher.is_none() { - return Ok(if failed { - ExitStatus::Failure - } else { - ExitStatus::Success + return Ok(match max_severity { + Severity::Info => ExitStatus::Success, + Severity::Warning => { + if terminal_settings.error_on_warning { + ExitStatus::Failure + } else { + ExitStatus::Success + } + } + Severity::Error => ExitStatus::Failure, + Severity::Fatal => ExitStatus::Error, }); } } From 73c3c142193cafd443cdaa0c9c1457445399dd38 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 28 Apr 2025 09:55:46 +0200 Subject: [PATCH 2/2] Use error code 101 --- crates/red_knot/src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/red_knot/src/main.rs b/crates/red_knot/src/main.rs index 94d233781fbd1..4ed4065c0c873 100644 --- a/crates/red_knot/src/main.rs +++ b/crates/red_knot/src/main.rs @@ -169,8 +169,12 @@ pub enum ExitStatus { /// Checking was successful but there were errors. Failure = 1, - /// Checking failed. + /// Checking failed due to an invocation error (e.g. the current directory no longer exists, incorrect CLI arguments, ...) Error = 2, + + /// Internal Red Knot error (panic, or any other error that isn't due to the user using the + /// program incorrectly or transient environment errors). + InternalError = 101, } impl Termination for ExitStatus { @@ -310,7 +314,7 @@ impl MainLoop { } } Severity::Error => ExitStatus::Failure, - Severity::Fatal => ExitStatus::Error, + Severity::Fatal => ExitStatus::InternalError, }); } }