rust_igraph/core/error.rs
1//! Error type for rust-igraph.
2//!
3//! Mirrors the most-used variants of `igraph_error_t` from the C core, with room to grow.
4//! Numeric error codes from `include/igraph_error.h` are kept as a separate enum so
5//! existing igraph-C tests can be reproduced precisely.
6
7use thiserror::Error;
8
9/// All errors returned from rust-igraph.
10///
11/// Variants are added as algorithms land; the initial set covers the cases the
12/// walking-skeleton (Phase 0) needs.
13#[derive(Debug, Error)]
14pub enum IgraphError {
15 /// Argument was outside its accepted range or otherwise invalid.
16 #[error("invalid argument: {0}")]
17 InvalidArgument(String),
18
19 /// A vertex id referred to a vertex that does not exist.
20 #[error("vertex {id} out of range (graph has {n} vertices)")]
21 VertexOutOfRange { id: u32, n: u32 },
22
23 /// An edge id referred to an edge that does not exist.
24 #[error("edge {id} out of range (graph has {m} edges)")]
25 EdgeOutOfRange { id: u32, m: u32 },
26
27 /// An I/O failure while reading or writing graph data.
28 #[error("I/O error: {0}")]
29 Io(#[from] std::io::Error),
30
31 /// Parsing a graph file failed.
32 #[error("parse error at line {line}: {message}")]
33 Parse { line: usize, message: String },
34
35 /// Operation is not supported (e.g. unweighted-only path requested on weighted graph).
36 #[error("unsupported: {0}")]
37 Unsupported(&'static str),
38
39 /// Numeric algorithm failed to converge within iteration budget.
40 #[error("did not converge after {iters} iterations (last residual {residual})")]
41 DidNotConverge { iters: usize, residual: f64 },
42
43 /// Catch-all for unexpected internal failures (bugs).
44 #[error("internal error: {0}")]
45 Internal(&'static str),
46}
47
48/// Convenience alias for `Result<T, IgraphError>`.
49pub type IgraphResult<T> = std::result::Result<T, IgraphError>;