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 #[error("Computation error: {0}")]
41 Computation(String),
42}
43
44impl GraphError {
45 pub fn graph_construction<S: Into<String>>(msg: S) -> Self {
46 GraphError::GraphConstruction(msg.into())
47 }
48
49 pub fn algorithm<S: Into<String>>(msg: S) -> Self {
50 GraphError::Algorithm(msg.into())
51 }
52
53 pub fn sql_parsing<S: Into<String>>(msg: S) -> Self {
54 GraphError::SqlParsing(msg.into())
55 }
56
57 pub fn invalid_parameter<S: Into<String>>(msg: S) -> Self {
58 GraphError::InvalidParameter(msg.into())
59 }
60
61 pub fn node_not_found<S: Into<String>>(node_id: S) -> Self {
62 GraphError::NodeNotFound(node_id.into())
63 }
64
65 pub fn computation_error<S: Into<String>>(msg: S) -> Self {
66 GraphError::Computation(msg.into())
67 }
68}