//! Errors with a message that is safe to show the user as-is. use std::fmt; #[derive(Debug)] pub struct UserError(pub String); impl UserError { pub fn new(text: impl Into) -> Self { Self(text.into()) } } impl fmt::Display for UserError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.0) } } impl std::error::Error for UserError {} /// `bail_user!("text {x}")` — stop the command with a message for the user. #[macro_export] macro_rules! bail_user { ($($arg:tt)*) => { return Err($crate::error::UserError::new(format!($($arg)*)).into()) }; }