Music with a live player, Last.fm, video downloads, games, AI chat, moderation, logging, a web dashboard and a Game Boy Activity. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
25 lines
624 B
Rust
25 lines
624 B
Rust
//! 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<String>) -> 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()) };
|
|
}
|