tftio_cli_common/
error.rs1use crate::runner::FatalCliError;
4
5#[must_use]
7pub fn fatal_error(
8 command: impl Into<String>,
9 json_output: bool,
10 message: impl Into<String>,
11) -> FatalCliError {
12 FatalCliError::new(command, json_output, message)
13}
14
15#[must_use]
17pub fn print_error(command: &str, json_output: bool, message: &str) -> i32 {
18 fatal_error(command, json_output, message).emit_and_exit_code()
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[test]
26 fn print_error_returns_failure_exit_code() {
27 assert_eq!(print_error("list", false, "bad"), 1);
28 }
29
30 #[test]
31 fn fatal_error_preserves_command_and_json_mode() {
32 let error = fatal_error("scan", true, "bad");
33 assert_eq!(error.command(), "scan");
34 assert!(error.json_output());
35 }
36}