const CONFIG_ERROR_CODE: &str = "E004";
#[derive(Debug)]
pub struct FallowError {
message: String,
}
#[expect(
clippy::unused_self,
clippy::unnecessary_wraps,
reason = "the getters keep the method shape that callers of the public analyze functions use"
)]
impl FallowError {
pub fn config(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
#[must_use]
pub fn code(&self) -> Option<&str> {
Some(CONFIG_ERROR_CODE)
}
#[must_use]
pub fn help(&self) -> Option<&str> {
None
}
#[must_use]
pub fn context(&self) -> Option<&str> {
None
}
}
impl std::fmt::Display for FallowError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"error[{CONFIG_ERROR_CODE}]: Configuration error: {}",
self.message
)
}
}
impl std::error::Error for FallowError {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn config_error_display_is_stable() {
let err = FallowError::config("invalid TOML");
assert_eq!(
err.to_string(),
"error[E004]: Configuration error: invalid TOML"
);
assert_eq!(err.code(), Some("E004"));
assert_eq!(err.help(), None);
assert_eq!(err.context(), None);
}
}