use crate::abi::SpanIR;
use crate::errors::MacroforgeError;
use thiserror::Error;
#[derive(Debug, Error, Clone, PartialEq, Eq)]
#[error("{message}")]
pub struct DeclarativeError {
pub message: String,
pub span: SpanIR,
pub help: Option<String>,
pub notes: Vec<String>,
}
impl DeclarativeError {
pub fn new(span: SpanIR, message: impl Into<String>) -> Self {
Self {
message: message.into(),
span,
help: None,
notes: Vec::new(),
}
}
pub fn with_help(mut self, help: impl Into<String>) -> Self {
self.help = Some(help.into());
self
}
pub fn with_note(mut self, note: impl Into<String>) -> Self {
self.notes.push(note.into());
self
}
}
impl From<DeclarativeError> for MacroforgeError {
fn from(err: DeclarativeError) -> Self {
MacroforgeError::new(err.span, err.message)
}
}