use kawauso_process::Invocation;
use kawauso_process::error::RunCommandError;
use thiserror::Error;
use crate::event::SendError;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum RunProcessError {
#[error("the command `{invocation}` was cancelled before it ended")]
#[non_exhaustive]
CancelledRun {
invocation: Invocation,
},
#[error(transparent)]
#[non_exhaustive]
UnrunnableCommand {
source: RunCommandError,
},
#[error("failed to report the output of the command `{invocation}`")]
#[non_exhaustive]
UnreportableOutput {
invocation: Invocation,
source: SendError,
},
}
#[cfg(test)]
mod tests {
#![allow(clippy::missing_panics_doc)]
use super::*;
#[test]
fn display_with_a_cancelled_run_names_the_command() {
let error = RunProcessError::CancelledRun {
invocation: Invocation::new("git").arg("status"),
};
let message = error.to_string();
assert_eq!(
message,
"the command `git status` was cancelled before it ended"
);
}
#[test]
fn display_with_unreportable_output_names_the_command() {
let error = RunProcessError::UnreportableOutput {
invocation: Invocation::new("git").arg("status"),
source: SendError(crate::event::Event::Message("lost".to_owned())),
};
let message = error.to_string();
assert_eq!(
message,
"failed to report the output of the command `git status`"
);
}
#[test]
fn trait_send() {
fn assert_send<T: Send>() {}
assert_send::<RunProcessError>();
}
#[test]
fn trait_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<RunProcessError>();
}
#[test]
fn trait_unpin() {
fn assert_unpin<T: Unpin>() {}
assert_unpin::<RunProcessError>();
}
}