use boltr::error::BoltError;
use kglite::api::KgError;
pub fn kg_to_bolt(err: KgError) -> BoltError {
BoltError::Query {
code: err.code().neo4j_status_code().into(),
message: err.to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
use kglite::api::KgErrorCode;
#[test]
fn syntax_error_maps_to_neo_clienterror_statement_syntaxerror() {
let err = KgError::CypherSyntax {
message: "unexpected token 'NOT'".into(),
line: Some(1),
col: Some(7),
};
let bolt = kg_to_bolt(err);
match bolt {
BoltError::Query { code, .. } => {
assert_eq!(code, "Neo.ClientError.Statement.SyntaxError");
}
other => panic!("expected Query, got {other:?}"),
}
}
#[test]
fn transaction_conflict_is_published_in_the_retriable_class() {
let code = KgErrorCode::TransactionConflict.neo4j_status_code();
assert!(
code.starts_with("Neo.TransientError."),
"OCC conflicts must be published in the driver-retriable class, got: {code}"
);
}
#[test]
fn every_code_has_a_neo4j_string_starting_with_neo_dot() {
for code in [
KgErrorCode::CypherSyntax,
KgErrorCode::CypherTimeout,
KgErrorCode::CypherExecution,
KgErrorCode::CypherTypeMismatch,
KgErrorCode::Schema,
KgErrorCode::Validation,
KgErrorCode::Expr,
KgErrorCode::NodeNotFound,
KgErrorCode::ConnectionNotFound,
KgErrorCode::PropertyNotFound,
KgErrorCode::FileNotFound,
KgErrorCode::FileFormat,
KgErrorCode::FileIo,
KgErrorCode::InvalidArgument,
KgErrorCode::MissingArgument,
KgErrorCode::Internal,
KgErrorCode::Cancelled,
KgErrorCode::ConstraintViolation,
KgErrorCode::ConstraintCreationFailed,
KgErrorCode::TransactionConflict,
] {
let s = code.neo4j_status_code();
assert!(
s.starts_with("Neo."),
"code {:?} mapped to non-Neo.* string: {}",
code,
s
);
assert_eq!(
s.split('.').count(),
4,
"code {:?} mapped to wrong-shaped string: {} (want 4 dotted segments)",
code,
s
);
}
}
}