use std::fmt;
pub fn detailed_message(message: &str) -> BasicInternalError {
message.into()
}
#[derive(Debug)]
pub struct BasicInternalError {
message: String,
}
impl From<&str> for BasicInternalError {
fn from(s: &str) -> Self {
Self {
message: s.to_string(),
}
}
}
impl std::error::Error for BasicInternalError {}
impl fmt::Display for BasicInternalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::*;
#[test]
fn test_message_internal() {
assert_eq!(
user_with_internal(
"Something bad happened.",
"Avoid bad things happening in future",
detailed_message("You got rate limited")
)
.message(),
"Oh no! Something bad happened.\n\nThis was caused by:\n - You got rate limited\n\nTo try and fix this, you can:\n - Avoid bad things happening in future"
);
assert_eq!(
system_with_internal(
"Something bad happened.",
"Avoid bad things happening in future",
detailed_message("You got rate limited")
)
.message(),
"Whoops! Something bad happened. (This isn't your fault)\n\nThis was caused by:\n - You got rate limited\n\nTo try and fix this, you can:\n - Avoid bad things happening in future"
);
}
}