32 lines
833 B
Rust
32 lines
833 B
Rust
use std::error::Error;
|
|
use std::fmt::{Display, Formatter};
|
|
|
|
#[derive(Debug)]
|
|
pub struct IllegalArgumentError {
|
|
message: String,
|
|
}
|
|
|
|
// Eventually we'll want support for source position, so we can highlight which argument(s)
|
|
// are wrong
|
|
impl IllegalArgumentError {
|
|
pub fn wrong_type(expected: &str, found: &str) -> Self {
|
|
Self {
|
|
message: format!("Expected {} but found {}", expected, found),
|
|
}
|
|
}
|
|
|
|
pub fn wrong_number(expected: usize, found: usize) -> Self {
|
|
Self {
|
|
message: format!("Expected {} argument(s) but found {}", expected, found),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Display for IllegalArgumentError {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "IllegalArgumentError: {}", self.message)
|
|
}
|
|
}
|
|
|
|
impl Error for IllegalArgumentError {}
|