Skip to content

Commit 9cb5005

Browse files
authored
Gracefully exit from kani-driver process (#2168)
When an error that was properly handled ocurrs in `kani-driver` we now gracefully exit and return ExitStatus::FAILURE. We still print all error context to keep a similar experiece to what it was before. However, this will no longer include the backtrace if users set RUST_BACKTRACE=1. The backtrace will still be included if you enable the debug logs and also enable the backtrace. I.e.: ```bash export RUST_BACKTRACE=1 export KANI_LOG=kani_driver=debug cargo kani ```
1 parent 48de656 commit 9cb5005

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

kani-driver/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(array_methods)]
55

66
use std::ffi::OsString;
7+
use std::process::ExitCode;
78

89
use anyhow::Result;
910

@@ -39,10 +40,20 @@ mod unsound_experiments;
3940
/// The main function for the `kani-driver`.
4041
/// The driver can be invoked via `cargo kani` and `kani` commands, which determines what kind of
4142
/// project should be verified.
42-
fn main() -> Result<()> {
43-
match determine_invocation_type(Vec::from_iter(std::env::args_os())) {
43+
fn main() -> ExitCode {
44+
let result = match determine_invocation_type(Vec::from_iter(std::env::args_os())) {
4445
InvocationType::CargoKani(args) => cargokani_main(args),
4546
InvocationType::Standalone => standalone_main(),
47+
};
48+
49+
if let Err(error) = result {
50+
// We are using the debug format for now to print the all the context.
51+
// We should consider creating a standard for error reporting.
52+
debug!(?error, "main_failure");
53+
util::error(&format!("{error:#}"));
54+
ExitCode::FAILURE
55+
} else {
56+
ExitCode::SUCCESS
4657
}
4758
}
4859

kani-driver/src/util.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,20 @@ pub fn specialized_harness_name(linked_obj: &Path, harness_filename: &str) -> Pa
8888
alter_extension(linked_obj, &format!("for-{harness_filename}.out"))
8989
}
9090

91-
/// Print a warning message. This will add a "warning:" tag before the message and style accordinly.
91+
/// Print a warning message. This will add a "warning:" tag before the message and style accordingly.
9292
pub fn warning(msg: &str) {
9393
let warning = console::style("warning:").bold().yellow();
9494
let msg_fmt = console::style(msg).bold();
9595
println!("{warning} {msg_fmt}")
9696
}
9797

98+
/// Print an error message. This will add an "error:" tag before the message and style accordingly.
99+
pub fn error(msg: &str) {
100+
let error = console::style("error:").bold().red();
101+
let msg_fmt = console::style(msg).bold();
102+
println!("{error} {msg_fmt}")
103+
}
104+
98105
#[cfg(test)]
99106
mod tests {
100107
use super::*;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
error: Crate crate_with_global_asm contains global ASM, which is not supported by Kani. Rerun with `--enable-unstable --ignore-global-asm` to suppress this error (**Verification results may be impacted**).
22
error: could not compile `crate_with_global_asm` due to previous error
3-
Error: cargo exited with status exit status: 101
3+
error: cargo exited with status exit status: 101
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: A proof harness named main was not found
1+
error: A proof harness named main was not found
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Skipped the following unsupported targets: 'lib'.
2-
Error: No supported targets were found.
2+
error: No supported targets were found.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: A proof harness named foo was not found
1+
error: A proof harness named foo was not found

0 commit comments

Comments
 (0)