This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new ab69445e5 Implement Debug for Error. (#2416)
ab69445e5 is described below

commit ab69445e58c9361d3686702c55d8de35c5ae830e
Author: Kousuke Saruta <[email protected]>
AuthorDate: Fri Aug 4 16:43:20 2023 +0900

    Implement Debug for Error. (#2416)
    
    (cherry picked from commit 16ae8952b00d1a14a7d31a14587cd408de041b31)
---
 lang/rust/avro/src/error.rs | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lang/rust/avro/src/error.rs b/lang/rust/avro/src/error.rs
index a82147530..661223313 100644
--- a/lang/rust/avro/src/error.rs
+++ b/lang/rust/avro/src/error.rs
@@ -19,9 +19,9 @@ use crate::{
     schema::{Name, SchemaKind},
     types::ValueKind,
 };
-use std::fmt;
+use std::{error::Error as _, fmt};
 
-#[derive(thiserror::Error, Debug)]
+#[derive(thiserror::Error)]
 pub enum Error {
     #[error("Bad Snappy CRC32; expected {expected:x} but got {actual:x}")]
     SnappyCrc32 { expected: u32, actual: u32 },
@@ -461,3 +461,13 @@ impl serde::de::Error for Error {
         Error::DeserializeValue(msg.to_string())
     }
 }
+
+impl fmt::Debug for Error {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let mut msg = self.to_string();
+        if let Some(e) = self.source() {
+            msg.extend([": ", &e.to_string()]);
+        }
+        write!(f, "{}", msg)
+    }
+}

Reply via email to