labast/src/errors.rs

45 lines
1.8 KiB
Rust
Raw Normal View History

2024-02-05 07:05:48 +00:00
use std::fmt::Display;
pub enum RunError {
RequestArgsInMainModule,
ExecuteItself(String),
FailToReadFile,
FailToGetCharFromConsole,
InvalidInputUShortInt,
PickTooDeep,
PickOutOfBounds,
FailToReadLineFromConsole,
UnknownLabel(u16),
InvalidExpressionUnknownOperator(String),
MemoryEmpty,
}
impl Display for RunError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RunError::RequestArgsInMainModule => write!(f, "Can't require arguments in the main module"),
RunError::ExecuteItself(mod_name) => write!(f, "Module {}: Can't execute itself", mod_name),
RunError::FailToReadFile => write!(f, "Unable to read file"),
RunError::FailToGetCharFromConsole => write!(f, "Failed to get character from console"),
RunError::InvalidInputUShortInt => write!(f, "Invalid input. Please enter a valid unsigned short integer"),
RunError::PickTooDeep => write!(f, "Picking too deep"),
RunError::PickOutOfBounds => write!(f, "Trying to get a value out of bounds"),
RunError::FailToReadLineFromConsole => write!(f, "Failed to read line from console"),
RunError::UnknownLabel(label_name) => write!(f, "Unknown label: {}", label_name),
RunError::InvalidExpressionUnknownOperator(name) => write!(f, "Invalid expression: unknown operator '{}'", name),
RunError::MemoryEmpty => write!(f, "No elements in memory!"),
}
}
}
pub enum ParseError {
DataNotAUInt(String, usize)
}
impl Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ParseError::DataNotAUInt(name, line) => write!(f, "Argument for {0} at {1} isn't a number", name, line),
}
}
}