Skip to content

Commit

Permalink
Add Ignore to current Bolt implementation (#204)
Browse files Browse the repository at this point in the history
* Implement ignore to possible responses for summary for current bolt implementation

* Run cargo fmt

* Fix clippy warnings

---------

Co-authored-by: Paul Horn <[email protected]>
  • Loading branch information
madchicken and knutwalker authored Dec 18, 2024
1 parent 4ac6f6a commit a56e2d2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
18 changes: 15 additions & 3 deletions lib/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ mod commit;
mod discard;
mod failure;
mod hello;
mod ignore;
mod pull;
mod record;
mod reset;
mod rollback;
mod run;
mod success;

use crate::messages::ignore::Ignore;
use crate::{
errors::{Error, Result},
types::{BoltMap, BoltWireFormat},
Expand All @@ -28,6 +30,7 @@ pub(crate) use success::Success;
pub enum BoltResponse {
Success(Success),
Failure(Failure),
Ignore(Ignore),
Record(Record),
}

Expand Down Expand Up @@ -222,15 +225,24 @@ impl BoltResponse {
let record = Record::parse(version, &mut response)?;
return Ok(BoltResponse::Record(record));
}
Err(Error::UnknownMessage(format!(
"unknown message {:?}",
response
if Ignore::can_parse(version, &response) {
let ignore = Ignore::parse(version, &mut response)?;
return Ok(BoltResponse::Ignore(ignore));
}
Err(Error::UnknownMessage(response.iter().fold(
"unknown message ".to_owned(),
|mut output, byte| {
use std::fmt::Write;
let _ = write!(output, "{:02X}", byte);
output
},
)))
}

pub fn into_error(self, msg: &'static str) -> Error {
match self {
BoltResponse::Failure(failure) => Error::Neo4j(failure.into_error()),
BoltResponse::Ignore(ignore) => Error::Neo4j(ignore.into_error()),
_ => Error::UnexpectedMessage(format!("unexpected response for {}: {:?}", msg, self)),
}
}
Expand Down
38 changes: 38 additions & 0 deletions lib/src/messages/ignore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::errors::Neo4jError;
use neo4rs_macros::BoltStruct;

#[derive(Debug, PartialEq, Clone, BoltStruct)]
#[signature(0xB0, 0x7E)]
pub struct Ignore;

impl Ignore {
pub(crate) fn into_error(self) -> Neo4jError {
Neo4jError::new(
"Neo.ServerError.Ignored".into(),
"The request was ignored by the server because it is in a FAILED or INTERRUPTED state"
.into(),
)
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::types::BoltWireFormat;
use crate::version::Version;
use bytes::Bytes;

#[test]
fn should_deserialize_success() {
let mut data = Bytes::from_static(&[0xB0, 0x7E]);

let failure: Ignore = Ignore::parse(Version::V4_1, &mut data).unwrap();
let failure = failure.into_error();

assert_eq!(failure.code(), "Neo.ServerError.Ignored");
assert_eq!(
failure.message(),
"The request was ignored by the server because it is in a FAILED or INTERRUPTED state"
);
}
}
2 changes: 1 addition & 1 deletion lib/src/types/serde/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'de> Deserialize<'de> for Offset<FixedOffset> {
}
struct OffsetVisitor;

impl<'de> Visitor<'de> for OffsetVisitor {
impl Visitor<'_> for OffsetVisitor {
type Value = FixedOffset;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down

0 comments on commit a56e2d2

Please sign in to comment.