Skip to main content

lora_executor/
errors.rs

1use crate::value::LoraValue;
2use lora_compiler::physical::PhysicalNodeId;
3use lora_store::{NodeId, RelationshipId};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7pub enum ExecutorError {
8    #[error("this query modifies the graph, but it was executed in read-only mode (CREATE at plan node {node_id:?})")]
9    ReadOnlyCreate { node_id: PhysicalNodeId },
10
11    #[error("this query modifies the graph, but it was executed in read-only mode (MERGE at plan node {node_id:?})")]
12    ReadOnlyMerge { node_id: PhysicalNodeId },
13
14    #[error("this query modifies the graph, but it was executed in read-only mode (DELETE at plan node {node_id:?})")]
15    ReadOnlyDelete { node_id: PhysicalNodeId },
16
17    #[error("this query modifies the graph, but it was executed in read-only mode (SET at plan node {node_id:?})")]
18    ReadOnlySet { node_id: PhysicalNodeId },
19
20    #[error("this query modifies the graph, but it was executed in read-only mode (REMOVE at plan node {node_id:?})")]
21    ReadOnlyRemove { node_id: PhysicalNodeId },
22
23    #[error("expected variable {var} to contain a node before expanding a relationship, but found {found}")]
24    ExpectedNodeForExpand { var: String, found: String },
25
26    #[error("expected a map value for properties, but found {found}")]
27    ExpectedPropertyMap { found: String },
28
29    #[error("grouping could not be executed because the group-by expression was not lowered to a variable")]
30    GroupByNotLowered,
31
32    #[error("aggregation could not be executed because the aggregate expression was not lowered to a variable")]
33    AggregateNotLowered,
34
35    #[error("variable-length relationships are not supported in CREATE")]
36    UnsupportedCreateRelationshipRange,
37
38    #[error("a CREATE relationship is missing its relationship type")]
39    MissingRelationshipType,
40
41    #[error("failed to create relationship `{rel_type}` from node {src} to node {dst}")]
42    RelationshipCreateFailed {
43        src: u64,
44        dst: u64,
45        rel_type: String,
46    },
47
48    #[error("cannot delete node {node_id} because it still has relationships; use DETACH DELETE to remove the node and its relationships")]
49    DeleteNodeWithRelationships { node_id: NodeId },
50
51    #[error("failed to delete relationship {rel_id}")]
52    DeleteRelationshipFailed { rel_id: RelationshipId },
53
54    #[error(
55        "DELETE can only be used with nodes, relationships, or lists of them, but found {found}"
56    )]
57    InvalidDeleteTarget { found: String },
58
59    #[error("REMOVE label can only be applied to a node, but found {found}")]
60    ExpectedNodeForRemoveLabels { found: String },
61
62    #[error("REMOVE referenced variable {var}, but that variable is not bound in the current row")]
63    UnboundVariableForRemove { var: String },
64
65    #[error("SET label can only be applied to a node, but found {found}")]
66    ExpectedNodeForSetLabels { found: String },
67
68    #[error("SET referenced variable {var}, but that variable is not bound in the current row")]
69    UnboundVariableForSet { var: String },
70
71    #[error("SET target must be a node or relationship, but found {found}")]
72    InvalidSetTarget { found: String },
73
74    #[error("REMOVE property currently only supports direct property expressions like n.name or r.weight")]
75    UnsupportedRemoveTarget,
76
77    #[error("REMOVE target must be a node or relationship property, but found {found}")]
78    InvalidRemoveTarget { found: String },
79
80    #[error(
81        "SET property currently only supports direct property expressions like n.name or r.weight"
82    )]
83    UnsupportedSetTarget,
84
85    #[error("expected variable {var} to contain a relationship during EXPAND, but found {found}")]
86    ExpectedRelationshipForExpand { var: String, found: String },
87
88    #[error("query deadline exceeded")]
89    QueryTimeout,
90
91    #[error("{0}")]
92    RuntimeError(String),
93}
94
95pub type ExecResult<T> = Result<T, ExecutorError>;
96
97pub fn value_kind(value: &LoraValue) -> String {
98    match value {
99        LoraValue::Null => "null".into(),
100        LoraValue::Bool(_) => "bool".into(),
101        LoraValue::Int(_) => "int".into(),
102        LoraValue::Float(_) => "float".into(),
103        LoraValue::String(_) => "string".into(),
104        LoraValue::List(_) => "list".into(),
105        LoraValue::Map(_) => "map".into(),
106        LoraValue::Node(_) => "node".into(),
107        LoraValue::Relationship(_) => "relationship".into(),
108        LoraValue::Path(_) => "path".into(),
109        LoraValue::Date(_) => "date".into(),
110        LoraValue::DateTime(_) => "datetime".into(),
111        LoraValue::LocalDateTime(_) => "localdatetime".into(),
112        LoraValue::Time(_) => "time".into(),
113        LoraValue::LocalTime(_) => "localtime".into(),
114        LoraValue::Duration(_) => "duration".into(),
115        LoraValue::Point(_) => "point".into(),
116        LoraValue::Vector(_) => "vector".into(),
117    }
118}