Skip to content

Commit a56e2d2

Browse files
Add Ignore to current Bolt implementation (#204)
* Implement ignore to possible responses for summary for current bolt implementation * Run cargo fmt * Fix clippy warnings --------- Co-authored-by: Paul Horn <[email protected]>
1 parent 4ac6f6a commit a56e2d2

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

lib/src/messages.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ mod commit;
44
mod discard;
55
mod failure;
66
mod hello;
7+
mod ignore;
78
mod pull;
89
mod record;
910
mod reset;
1011
mod rollback;
1112
mod run;
1213
mod success;
1314

15+
use crate::messages::ignore::Ignore;
1416
use crate::{
1517
errors::{Error, Result},
1618
types::{BoltMap, BoltWireFormat},
@@ -28,6 +30,7 @@ pub(crate) use success::Success;
2830
pub enum BoltResponse {
2931
Success(Success),
3032
Failure(Failure),
33+
Ignore(Ignore),
3134
Record(Record),
3235
}
3336

@@ -222,15 +225,24 @@ impl BoltResponse {
222225
let record = Record::parse(version, &mut response)?;
223226
return Ok(BoltResponse::Record(record));
224227
}
225-
Err(Error::UnknownMessage(format!(
226-
"unknown message {:?}",
227-
response
228+
if Ignore::can_parse(version, &response) {
229+
let ignore = Ignore::parse(version, &mut response)?;
230+
return Ok(BoltResponse::Ignore(ignore));
231+
}
232+
Err(Error::UnknownMessage(response.iter().fold(
233+
"unknown message ".to_owned(),
234+
|mut output, byte| {
235+
use std::fmt::Write;
236+
let _ = write!(output, "{:02X}", byte);
237+
output
238+
},
228239
)))
229240
}
230241

231242
pub fn into_error(self, msg: &'static str) -> Error {
232243
match self {
233244
BoltResponse::Failure(failure) => Error::Neo4j(failure.into_error()),
245+
BoltResponse::Ignore(ignore) => Error::Neo4j(ignore.into_error()),
234246
_ => Error::UnexpectedMessage(format!("unexpected response for {}: {:?}", msg, self)),
235247
}
236248
}

lib/src/messages/ignore.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::errors::Neo4jError;
2+
use neo4rs_macros::BoltStruct;
3+
4+
#[derive(Debug, PartialEq, Clone, BoltStruct)]
5+
#[signature(0xB0, 0x7E)]
6+
pub struct Ignore;
7+
8+
impl Ignore {
9+
pub(crate) fn into_error(self) -> Neo4jError {
10+
Neo4jError::new(
11+
"Neo.ServerError.Ignored".into(),
12+
"The request was ignored by the server because it is in a FAILED or INTERRUPTED state"
13+
.into(),
14+
)
15+
}
16+
}
17+
18+
#[cfg(test)]
19+
mod tests {
20+
use super::*;
21+
use crate::types::BoltWireFormat;
22+
use crate::version::Version;
23+
use bytes::Bytes;
24+
25+
#[test]
26+
fn should_deserialize_success() {
27+
let mut data = Bytes::from_static(&[0xB0, 0x7E]);
28+
29+
let failure: Ignore = Ignore::parse(Version::V4_1, &mut data).unwrap();
30+
let failure = failure.into_error();
31+
32+
assert_eq!(failure.code(), "Neo.ServerError.Ignored");
33+
assert_eq!(
34+
failure.message(),
35+
"The request was ignored by the server because it is in a FAILED or INTERRUPTED state"
36+
);
37+
}
38+
}

lib/src/types/serde/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'de> Deserialize<'de> for Offset<FixedOffset> {
168168
}
169169
struct OffsetVisitor;
170170

171-
impl<'de> Visitor<'de> for OffsetVisitor {
171+
impl Visitor<'_> for OffsetVisitor {
172172
type Value = FixedOffset;
173173

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

0 commit comments

Comments
 (0)