use thiserror::Error;
pub type Result<T> = std::result::Result<T, SparsifierError>;
#[derive(Error, Debug)]
pub enum SparsifierError {
#[error("vertex {0} is out of bounds (graph has {1} vertices)")]
VertexOutOfBounds(usize, usize),
#[error("edge ({0}, {1}) not found")]
EdgeNotFound(usize, usize),
#[error("edge ({0}, {1}) already exists")]
EdgeAlreadyExists(usize, usize),
#[error("invalid edge weight {0}: must be positive and finite")]
InvalidWeight(f64),
#[error("invalid epsilon {0}: must be in (0, 1)")]
InvalidEpsilon(f64),
#[error("edge budget {budget} is too small for {vertices} vertices (minimum {minimum})")]
BudgetTooSmall {
budget: usize,
vertices: usize,
minimum: usize,
},
#[error("cannot sparsify an empty graph")]
EmptyGraph,
#[error("spectral audit failed: max relative error {max_error:.4} exceeds threshold {threshold:.4}")]
AuditFailed {
max_error: f64,
threshold: f64,
},
#[error("numerical error: {0}")]
Numerical(String),
#[error("internal error: {0}")]
Internal(String),
}