#[derive(Debug, Clone)]
pub struct ParseDiagnostic {
pub message: String,
pub start: usize,
pub end: usize,
}
#[derive(Debug, Error)]
pub enum FrontendError {
#[error("Solidity parsing failed:\n{0}")]
Parse(String),
#[error("Solidity parsing failed with {} error(s)", .0.len())]
ParseDiagnostics(Vec<ParseDiagnostic>),
#[error("Unsupported Solidity version: {0}")]
UnsupportedVersion(String),
#[error("Failed to resolve import '{path}': {reason}")]
ImportError { path: String, reason: String },
#[error("Contract '{0}' not found in source")]
ContractNotFound(String),
}
impl FrontendError {
pub fn parse_at(line: usize, column: usize, message: impl Into<String>) -> Self {
Self::Parse(format!("{}:{}: {}", line, column, message.into()))
}
pub fn import_error(path: impl Into<String>, reason: impl Into<String>) -> Self {
Self::ImportError {
path: path.into(),
reason: reason.into(),
}
}
pub fn is_recoverable(&self) -> bool {
matches!(self, Self::UnsupportedVersion(_))
}
}