use std::io;
use std::path::PathBuf;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum TransactionErrorKind {
AlreadyActive,
NotActive,
RollbackOnly,
InvalidSavepoint,
TimedOut,
Cancelled,
ResourceLimit,
Conflict,
StoragePoisoned,
}
impl std::fmt::Display for TransactionErrorKind {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(match self {
Self::AlreadyActive => "a transaction is already active",
Self::NotActive => "no transaction is active",
Self::RollbackOnly => "the transaction is rollback-only",
Self::InvalidSavepoint => "the savepoint is not valid for this transaction",
Self::TimedOut => "the transaction deadline was exceeded",
Self::Cancelled => "the transaction was cancelled",
Self::ResourceLimit => "the transaction workspace resource limit was exceeded",
Self::Conflict => {
"the transaction conflicted with a concurrently committed transaction"
}
Self::StoragePoisoned => "the writable storage requires recovery before reuse",
})
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Neo4jStoreError {
#[error("Neo4j database path is not a directory: {path}")]
NotADirectory { path: PathBuf },
#[error("required Neo4j store file is missing: {path}")]
MissingFile { path: PathBuf },
#[error("failed to read Neo4j store file {path}: {source}")]
Read {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("failed to write Neo4j store file {path}: {source}")]
Write {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("Neo4j database is locked by another process: {path}")]
DatabaseLocked { path: PathBuf },
#[error("failed to lock Neo4j database at {path}: {source}")]
DatabaseLock {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("invalid littlegraph journal {path}: {message}")]
InvalidJournal { path: PathBuf, message: String },
#[error("Neo4j database is not supported for writable access: {path}: {message}")]
UnsupportedWritableStore { path: PathBuf, message: String },
#[error(
"Neo4j commit recovery failed for {path}: commit error: {commit_error}; recovery error: {recovery_error}"
)]
CommitRecovery {
path: PathBuf,
commit_error: Box<Error>,
#[source]
recovery_error: Box<Error>,
},
#[error(
"truncated Neo4j store file {path} at offset {offset}: expected {expected} bytes, found {actual}"
)]
Truncated {
path: PathBuf,
offset: u64,
expected: usize,
actual: usize,
},
#[error("invalid Neo4j metadata in {path} at offset {offset}: {message}")]
InvalidMetadata {
path: PathBuf,
offset: u64,
message: String,
},
#[error("invalid Neo4j page layout for {path}: {message}")]
InvalidPageLayout { path: PathBuf, message: String },
#[error(
"Neo4j {record_type} record {record_id} is outside {path}: byte offset {offset}, record size {record_size}, file size {file_size}"
)]
RecordOutOfBounds {
path: PathBuf,
record_type: String,
record_id: u64,
offset: u64,
record_size: usize,
file_size: u64,
},
#[error(
"failed to read Neo4j {record_type} record {record_id} from {path} at offset {offset}: {source}"
)]
RecordRead {
path: PathBuf,
record_type: String,
record_id: u64,
offset: u64,
#[source]
source: io::Error,
},
#[error(
"failed to write Neo4j {record_type} record {record_id} to {path} at offset {offset}: {source}"
)]
RecordWrite {
path: PathBuf,
record_type: String,
record_id: u64,
offset: u64,
#[source]
source: io::Error,
},
#[error(
"invalid Neo4j {record_type} record {record_id} in {path} at offset {offset} ({context}): {message}"
)]
InvalidRecord {
path: PathBuf,
record_type: String,
record_id: u64,
offset: u64,
context: String,
message: String,
},
#[error(
"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"
)]
UnsupportedFormat {
path: PathBuf,
storage_engine: String,
format_name: String,
major_version: i8,
minor_version: i8,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("failed to load data: {0}")]
DataLoad(String),
#[error("invalid graph reference: {0}")]
InvalidGraphReference(String),
#[error("failed to parse Cypher query: {0}")]
Parse(String),
#[error("unsupported query feature: {0}")]
UnsupportedQueryFeature(String),
#[error("write queries are not supported: {0}")]
UnsupportedWriteQuery(String),
#[error("writing is not allowed in a read-only transaction")]
AccessMode,
#[error("invalid query: {0}")]
Validation(String),
#[error("unknown procedure: {name}")]
UnknownProcedure { name: String },
#[error("procedure `{name}` is deferred: {reason}")]
DeferredProcedure { name: String, reason: String },
#[error("invalid call to procedure `{name}`: {message}")]
InvalidProcedureCall { name: String, message: String },
#[error("procedure mode is not supported for `{name}`: {mode}")]
UnsupportedProcedureMode { name: String, mode: String },
#[error("query execution failed: {0}")]
Execution(String),
#[error("transaction error: {0}")]
Transaction(TransactionErrorKind),
#[error("console error: {0}")]
Console(String),
#[error(transparent)]
Neo4jStore(#[from] Neo4jStoreError),
#[error("io error: {0}")]
Io(#[from] io::Error),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
}
pub type Result<T> = std::result::Result<T, Error>;