Skip to main content

lance_graph/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright The Lance Authors
3
4//! Error types for the Lance graph query engine
5
6use snafu::{prelude::*, Location};
7
8pub type Result<T> = std::result::Result<T, GraphError>;
9
10/// Errors that can occur during graph query processing
11#[derive(Debug, Snafu)]
12#[snafu(visibility(pub(crate)))]
13pub enum GraphError {
14    /// Error parsing Cypher query syntax
15    #[snafu(display("Cypher parse error at position {position}: {message}"))]
16    ParseError {
17        message: String,
18        position: usize,
19        location: Location,
20    },
21
22    /// Error with graph configuration
23    #[snafu(display("Graph configuration error: {message}"))]
24    ConfigError { message: String, location: Location },
25
26    /// Error during query planning
27    #[snafu(display("Query planning error: {message}"))]
28    PlanError { message: String, location: Location },
29
30    /// Error during query execution
31    #[snafu(display("Query execution error: {message}"))]
32    ExecutionError { message: String, location: Location },
33
34    /// Unsupported Cypher feature
35    #[snafu(display("Unsupported Cypher feature: {feature}"))]
36    UnsupportedFeature { feature: String, location: Location },
37
38    /// Invalid graph pattern
39    #[snafu(display("Invalid graph pattern: {message}"))]
40    InvalidPattern { message: String, location: Location },
41
42    /// DataFusion integration error
43    #[snafu(display("DataFusion error: {source}"))]
44    DataFusion {
45        source: datafusion_common::DataFusionError,
46        location: Location,
47    },
48
49    /// Lance core error
50    #[snafu(display("Lance core error: {source}"))]
51    LanceCore {
52        source: lance::Error,
53        location: Location,
54    },
55
56    /// Arrow error
57    #[snafu(display("Arrow error: {source}"))]
58    Arrow {
59        source: arrow::error::ArrowError,
60        location: Location,
61    },
62}
63
64impl From<datafusion_common::DataFusionError> for GraphError {
65    fn from(source: datafusion_common::DataFusionError) -> Self {
66        Self::DataFusion {
67            source,
68            location: Location::new(file!(), line!(), column!()),
69        }
70    }
71}
72
73impl From<lance::Error> for GraphError {
74    fn from(source: lance::Error) -> Self {
75        Self::LanceCore {
76            source,
77            location: Location::new(file!(), line!(), column!()),
78        }
79    }
80}
81
82impl From<arrow::error::ArrowError> for GraphError {
83    fn from(source: arrow::error::ArrowError) -> Self {
84        Self::Arrow {
85            source,
86            location: Location::new(file!(), line!(), column!()),
87        }
88    }
89}