1use std::io;
2use std::path::PathBuf;
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum TransactionErrorKind {
7 AlreadyActive,
8 NotActive,
9 RollbackOnly,
10 InvalidSavepoint,
11 TimedOut,
12 Cancelled,
13 ResourceLimit,
14 Conflict,
15 StoragePoisoned,
16}
17
18impl std::fmt::Display for TransactionErrorKind {
19 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 formatter.write_str(match self {
21 Self::AlreadyActive => "a transaction is already active",
22 Self::NotActive => "no transaction is active",
23 Self::RollbackOnly => "the transaction is rollback-only",
24 Self::InvalidSavepoint => "the savepoint is not valid for this transaction",
25 Self::TimedOut => "the transaction deadline was exceeded",
26 Self::Cancelled => "the transaction was cancelled",
27 Self::ResourceLimit => "the transaction workspace resource limit was exceeded",
28 Self::Conflict => {
29 "the transaction conflicted with a concurrently committed transaction"
30 }
31 Self::StoragePoisoned => "the writable storage requires recovery before reuse",
32 })
33 }
34}
35
36#[derive(Debug, thiserror::Error)]
37#[non_exhaustive]
38pub enum Neo4jStoreError {
39 #[error("Neo4j database path is not a directory: {path}")]
40 NotADirectory { path: PathBuf },
41 #[error("required Neo4j store file is missing: {path}")]
42 MissingFile { path: PathBuf },
43 #[error("failed to read Neo4j store file {path}: {source}")]
44 Read {
45 path: PathBuf,
46 #[source]
47 source: io::Error,
48 },
49 #[error("failed to write Neo4j store file {path}: {source}")]
50 Write {
51 path: PathBuf,
52 #[source]
53 source: io::Error,
54 },
55 #[error("Neo4j database is locked by another process: {path}")]
56 DatabaseLocked { path: PathBuf },
57 #[error("failed to lock Neo4j database at {path}: {source}")]
58 DatabaseLock {
59 path: PathBuf,
60 #[source]
61 source: io::Error,
62 },
63 #[error("invalid littlegraph journal {path}: {message}")]
64 InvalidJournal { path: PathBuf, message: String },
65 #[error("Neo4j database is not supported for writable access: {path}: {message}")]
66 UnsupportedWritableStore { path: PathBuf, message: String },
67 #[error(
68 "Neo4j commit recovery failed for {path}: commit error: {commit_error}; recovery error: {recovery_error}"
69 )]
70 CommitRecovery {
71 path: PathBuf,
72 commit_error: Box<Error>,
73 #[source]
74 recovery_error: Box<Error>,
75 },
76 #[error(
77 "truncated Neo4j store file {path} at offset {offset}: expected {expected} bytes, found {actual}"
78 )]
79 Truncated {
80 path: PathBuf,
81 offset: u64,
82 expected: usize,
83 actual: usize,
84 },
85 #[error("invalid Neo4j metadata in {path} at offset {offset}: {message}")]
86 InvalidMetadata {
87 path: PathBuf,
88 offset: u64,
89 message: String,
90 },
91 #[error("invalid Neo4j page layout for {path}: {message}")]
92 InvalidPageLayout { path: PathBuf, message: String },
93 #[error(
94 "Neo4j {record_type} record {record_id} is outside {path}: byte offset {offset}, record size {record_size}, file size {file_size}"
95 )]
96 RecordOutOfBounds {
97 path: PathBuf,
98 record_type: String,
99 record_id: u64,
100 offset: u64,
101 record_size: usize,
102 file_size: u64,
103 },
104 #[error(
105 "failed to read Neo4j {record_type} record {record_id} from {path} at offset {offset}: {source}"
106 )]
107 RecordRead {
108 path: PathBuf,
109 record_type: String,
110 record_id: u64,
111 offset: u64,
112 #[source]
113 source: io::Error,
114 },
115 #[error(
116 "failed to write Neo4j {record_type} record {record_id} to {path} at offset {offset}: {source}"
117 )]
118 RecordWrite {
119 path: PathBuf,
120 record_type: String,
121 record_id: u64,
122 offset: u64,
123 #[source]
124 source: io::Error,
125 },
126 #[error(
127 "invalid Neo4j {record_type} record {record_id} in {path} at offset {offset} ({context}): {message}"
128 )]
129 InvalidRecord {
130 path: PathBuf,
131 record_type: String,
132 record_id: u64,
133 offset: u64,
134 context: String,
135 message: String,
136 },
137 #[error(
138 "unsupported Neo4j store format in {path}: storage engine '{storage_engine}', format '{format_name}', version {major_version}.{minor_version}; supported formats are record/standard-1.1 and record/aligned-1.1"
139 )]
140 UnsupportedFormat {
141 path: PathBuf,
142 storage_engine: String,
143 format_name: String,
144 major_version: i8,
145 minor_version: i8,
146 },
147}
148
149#[derive(Debug, thiserror::Error)]
150#[non_exhaustive]
151pub enum Error {
152 #[error("failed to load data: {0}")]
153 DataLoad(String),
154 #[error("invalid graph reference: {0}")]
155 InvalidGraphReference(String),
156 #[error("failed to parse Cypher query: {0}")]
157 Parse(String),
158 #[error("unsupported query feature: {0}")]
159 UnsupportedQueryFeature(String),
160 #[error("write queries are not supported: {0}")]
161 UnsupportedWriteQuery(String),
162 #[error("writing is not allowed in a read-only transaction")]
163 AccessMode,
164 #[error("invalid query: {0}")]
165 Validation(String),
166 #[error("unknown procedure: {name}")]
167 UnknownProcedure { name: String },
168 #[error("procedure `{name}` is deferred: {reason}")]
169 DeferredProcedure { name: String, reason: String },
170 #[error("invalid call to procedure `{name}`: {message}")]
171 InvalidProcedureCall { name: String, message: String },
172 #[error("procedure mode is not supported for `{name}`: {mode}")]
173 UnsupportedProcedureMode { name: String, mode: String },
174 #[error("query execution failed: {0}")]
175 Execution(String),
176 #[error("transaction error: {0}")]
177 Transaction(TransactionErrorKind),
178 #[error("console error: {0}")]
179 Console(String),
180 #[error(transparent)]
181 Neo4jStore(#[from] Neo4jStoreError),
182 #[error("io error: {0}")]
183 Io(#[from] io::Error),
184 #[error("json error: {0}")]
185 Json(#[from] serde_json::Error),
186}
187
188pub type Result<T> = std::result::Result<T, Error>;