use crate::limits::LimitExceeded;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("parse error{}: {message}", if *line > 0 { format!(" at line {}, column {}", line, column) } else { String::new() })]
Parse {
message: String,
line: usize,
column: usize,
},
#[error("execution error: {0}")]
Execution(String),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("resource limit exceeded: {0}")]
ResourceLimit(#[from] LimitExceeded),
#[error("network error: {0}")]
Network(String),
#[error("regex error: {0}")]
Regex(#[from] regex::Error),
#[error("execution cancelled")]
Cancelled,
#[error("internal error: {0}")]
Internal(String),
}
impl Error {
pub fn parse_at(message: impl Into<String>, line: usize, column: usize) -> Self {
Self::Parse {
message: message.into(),
line,
column,
}
}
pub fn parse(message: impl Into<String>) -> Self {
Self::Parse {
message: message.into(),
line: 0,
column: 0,
}
}
}