pub(crate) const fn interrupt_exit_code() -> i32 {
130
}
pub(crate) fn command_failure_exit_code(msg: &str) -> i32 {
let m = msg.to_ascii_lowercase();
let not_found = m.contains("executable file not found")
|| m.contains("not found in $path")
|| (m.contains("oci runtime") && m.contains("no such file"));
let not_executable = m.contains("exec format error")
|| m.contains("not executable")
|| (m.contains("oci runtime") && m.contains("permission denied"));
if not_found {
127
} else if not_executable {
126
} else {
1
}
}
pub(crate) fn print_error(e: &podup::ComposeError) {
use std::io::Write;
let style = podup::ui::error_style();
let mut err = anstream::stderr();
let _ = writeln!(
err,
"podup: {}error:{} {e}",
style.render(),
style.render_reset()
);
}
#[cfg(test)]
mod exit_code_tests {
use super::command_failure_exit_code;
#[test]
fn not_found_maps_to_127() {
assert_eq!(
command_failure_exit_code(
"podman error: crun: executable file `foo` not found in $PATH: \
No such file or directory: OCI runtime command not found error"
),
127
);
assert_eq!(
command_failure_exit_code("OCI runtime error: ...: no such file or directory"),
127
);
}
#[test]
fn not_executable_maps_to_126() {
assert_eq!(
command_failure_exit_code("OCI runtime error: permission denied"),
126
);
assert_eq!(command_failure_exit_code("exec format error"), 126);
}
#[test]
fn unrelated_errors_map_to_1() {
assert_eq!(command_failure_exit_code("some other failure"), 1);
assert_eq!(command_failure_exit_code("container is restarting"), 1);
}
}