Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions crates/red_knot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -269,12 +273,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)");
Expand All @@ -289,13 +287,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!(
Expand All @@ -306,10 +304,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::InternalError,
});
}
}
Expand Down
Loading