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