1
2pub type Result<T> = std::result::Result<T, GraphError>;
3
4#[derive(Debug, thiserror::Error)]
5pub enum GraphError {
6 #[error("Arrow error: {0}")]
7 Arrow(#[from] arrow::error::ArrowError),
8
9 #[error("DataFusion error: {0}")]
10 DataFusion(#[from] datafusion_common::DataFusionError),
11
12 #[error("Graph construction error: {0}")]
13 GraphConstruction(String),
14
15 #[error("Algorithm error: {0}")]
16 Algorithm(String),
17
18 #[error("SQL parsing error: {0}")]
19 SqlParsing(String),
20
21 #[error("Invalid parameter: {0}")]
22 InvalidParameter(String),
23
24 #[error("Node not found: {0}")]
25 NodeNotFound(String),
26
27 #[error("Edge not found: source={0}, target={1}")]
28 EdgeNotFound(String, String),
29
30 #[error("Graph is empty")]
31 EmptyGraph,
32
33 #[error("IO error: {0}")]
34 Io(#[from] std::io::Error),
35
36 #[error("Serialization error: {0}")]
37 Serialization(#[from] serde_json::Error),
38
39 #[error("Computation error: {0}")]
40 Computation(String),
41}
42
43impl GraphError {
44 pub fn graph_construction<S: Into<String>>(msg: S) -> Self {
45 GraphError::GraphConstruction(msg.into())
46 }
47
48 pub fn algorithm<S: Into<String>>(msg: S) -> Self {
49 GraphError::Algorithm(msg.into())
50 }
51
52 pub fn sql_parsing<S: Into<String>>(msg: S) -> Self {
53 GraphError::SqlParsing(msg.into())
54 }
55
56 pub fn invalid_parameter<S: Into<String>>(msg: S) -> Self {
57 GraphError::InvalidParameter(msg.into())
58 }
59
60 pub fn node_not_found<S: Into<String>>(node_id: S) -> Self {
61 GraphError::NodeNotFound(node_id.into())
62 }
63
64 pub fn computation_error<S: Into<String>>(msg: S) -> Self {
65 GraphError::Computation(msg.into())
66 }
67}