use thiserror::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrorCode {
E01001, E01002, E01003, E01004, E01005,
E02001, E02002, E02003, E02004,
E03001, E03002, E03003, E03004, E03005,
E04001, E04002, E04003, E04004, E04005, E04006,
E05001, E05002, E05003, }
impl std::fmt::Display for ErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Debug, Clone, Default)]
pub struct SourceLocation {
pub line: usize,
pub column: usize,
pub context: String,
}
#[derive(Debug, Error)]
#[error("[{code}] {message}")]
pub struct DelbinError {
pub code: ErrorCode,
pub message: String,
pub location: Option<SourceLocation>,
pub hint: Option<String>,
}
impl DelbinError {
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self {
Self {
code,
message: message.into(),
location: None,
hint: None,
}
}
pub fn with_location(mut self, location: SourceLocation) -> Self {
self.location = Some(location);
self
}
pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
self.hint = Some(hint.into());
self
}
}
#[derive(Debug, Clone)]
pub struct DelbinWarning {
pub code: WarningCode,
pub message: String,
pub location: Option<SourceLocation>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WarningCode {
W03001, W03002, W04001, }
pub type Result<T> = std::result::Result<T, DelbinError>;