From 74c38fe32af42b5f66514c2e367e2917bad7038c Mon Sep 17 00:00:00 2001 From: Thijs Cadier Date: Wed, 2 Sep 2015 21:59:39 +0200 Subject: [PATCH] Show code and domain in bsonc error debug output --- src/bsonc.rs | 2 +- src/error.rs | 8 +++++++- tests/bulk_operation.rs | 2 +- tests/collection.rs | 2 +- tests/cursor.rs | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bsonc.rs b/src/bsonc.rs index 096a112..64263c1 100644 --- a/src/bsonc.rs +++ b/src/bsonc.rs @@ -147,6 +147,6 @@ mod tests { assert!(bsonc_result.is_err()); let error_message = format!("{:?}", bsonc_result.err().unwrap()); - assert!(error_message.starts_with("MongoError (BsoncError: parse error: premature EOF")); + assert!(error_message.starts_with("MongoError (BsoncError: Client/StreamInvalidType - parse error: premature EOF")); } } diff --git a/src/error.rs b/src/error.rs index 3156ddb..cec18b5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -226,7 +226,13 @@ impl BsoncError { impl fmt::Debug for BsoncError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "BsoncError: {}", &self.get_message()) + write!( + f, + "BsoncError: {:?}/{:?} - {}", + &self.domain(), + &self.code(), + &self.get_message() + ) } } diff --git a/tests/bulk_operation.rs b/tests/bulk_operation.rs index fe796f7..b9cdff0 100644 --- a/tests/bulk_operation.rs +++ b/tests/bulk_operation.rs @@ -15,7 +15,7 @@ fn test_execute_error() { assert!(result.is_err()); let error_message = format!("{:?}", result.err().unwrap()); - assert_eq!(error_message, "MongoError (BsoncError: Cannot do an empty bulk write)"); + assert_eq!(error_message, "MongoError (BsoncError: Command/CommandInvalidArg - Cannot do an empty bulk write)"); } #[test] diff --git a/tests/collection.rs b/tests/collection.rs index 31cb2f9..b989172 100644 --- a/tests/collection.rs +++ b/tests/collection.rs @@ -133,7 +133,7 @@ fn test_insert_failure() { let result = collection.insert(&document, None); assert!(result.is_err()); assert_eq!( - "MongoError (BsoncError: Failed to connect to target host: localhost:27018)", + "MongoError (BsoncError: Stream/StreamConnect - Failed to connect to target host: localhost:27018)", format!("{:?}", result.err().unwrap()) ); } diff --git a/tests/cursor.rs b/tests/cursor.rs index 5ed0236..382fb5d 100644 --- a/tests/cursor.rs +++ b/tests/cursor.rs @@ -52,7 +52,7 @@ fn test_tailing_cursor() { let failing_result = failing_cursor.into_iter().next().unwrap(); assert!(failing_result.is_err()); assert_eq!( - "MongoError (BsoncError: Unable to execute query: error processing query: ns=rust_test.not_capped limit=0 skip=0\nTree: $and\nSort: {}\nProj: {}\n tailable cursor requested on non capped collection)", + "MongoError (BsoncError: Query/Unknown - Unable to execute query: error processing query: ns=rust_test.not_capped limit=0 skip=0\nTree: $and\nSort: {}\nProj: {}\n tailable cursor requested on non capped collection)", format!("{:?}", failing_result.err().unwrap()) );