simple_graph/
error.rs

1/// Custom Result type with two generic parameters for user convenience
2pub type Result<T, E = GraphOperationError> = std::result::Result<T, E>;
3
4/// Describes possible errors that might happen when user interacts with graph
5#[derive(thiserror::Error, Debug, Eq, PartialEq)]
6pub enum GraphOperationError {
7    /// when user trying to create vertex with the same data
8    #[error("this vertex_id already exists in the graph")]
9    VertexAlreadyExists,
10    /// when user trying to get/remove vertex by id and it doesn't exist
11    #[error("this vertex_id does not exist in the graph")]
12    VertexDoesNotExist,
13    /// when user trying to find edge by two vertices and it's failed
14    #[error("unable to find edge in graph between two vertices")]
15    EdgeDoesNotExist,
16}
17
18/// Describes possible errors that might happen during parsing the Trivial Graph Format
19#[derive(thiserror::Error, Debug, Eq, PartialEq)]
20pub enum ParseGraphError {
21    /// `(line: usize)`
22    #[error("incorrect vertex definition at line {0}")]
23    VertexDefinition(usize),
24    /// `(line: usize)`
25    #[error("incorrect edge definition at line {0}")]
26    EdgeDefinition(usize),
27
28    #[error("vertex with index {0} already defined, check line {1}")]
29    /// `(vertex_index: usize, line: usize)`
30    VertexAlreadyDefined(usize, usize),
31    /// `(from_index: usize, to_index: usize, line: usize)`
32    #[error("failed to join vertices with ids {0}, {1} because they are not defined at line {2}")]
33    VerticesNotDefined(usize, usize, usize),
34
35    /// `(line: usize)`
36    #[error("failed to parse index of the vertex or edge at line {0}")]
37    ParseInt(usize),
38    /// `(line: usize)`
39    #[error("failed to parse label data of the vertex or edge at line {0}")]
40    ParseLabel(usize),
41
42    /// internal error with graphs API
43    #[error("some graph operation failed: {0} at line {1}")]
44    GraphError(GraphOperationError, usize),
45}