#[derive(Debug, Error)]
pub enum LeoError {
#[error(transparent)]
Formatted(#[from] crate::Formatted),
#[error(transparent)]
Backtraced(#[from] crate::Backtraced),
#[error("")]
LastErrorCode(i32),
#[error(transparent)]
SnarkVM(#[from] anyhow::Error),
}
impl LeoError {
pub fn error_code(&self) -> String {
use LeoError::*;
match self {
Formatted(e) => e.error_code(),
Backtraced(e) => e.error_code(),
LastErrorCode(_) => unreachable!(),
SnarkVM(_) => "SnarkVM Error".to_string(),
}
}
pub fn exit_code(&self) -> i32 {
use LeoError::*;
match self {
Formatted(e) => e.exit_code(),
Backtraced(e) => e.exit_code(),
LastErrorCode(code) => *code,
SnarkVM(_) => 11000,
}
}
pub fn diagnostic_view(&self) -> Option<crate::DiagnosticView<'_>> {
match self {
LeoError::Formatted(formatted) => Some(formatted.diagnostic_view()),
LeoError::Backtraced(_) | LeoError::LastErrorCode(_) | LeoError::SnarkVM(_) => None,
}
}
pub fn is_last_error_code(&self) -> bool {
matches!(self, LeoError::LastErrorCode(_))
}
}
#[derive(Debug, Error)]
pub enum LeoWarning {
#[error(transparent)]
Formatted(#[from] crate::Formatted),
}
impl LeoWarning {
pub fn error_code(&self) -> String {
use LeoWarning::*;
match self {
Formatted(w) => w.warning_code(),
}
}
pub fn diagnostic_view(&self) -> Option<crate::DiagnosticView<'_>> {
match self {
LeoWarning::Formatted(formatted) => Some(formatted.diagnostic_view()),
}
}
}
pub type Result<T, E = LeoError> = core::result::Result<T, E>;