Skip to content

Commit

Permalink
Implement Debug for Error. (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarutak authored Aug 4, 2023
1 parent db359f5 commit 16ae895
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lang/rust/avro/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -464,3 +464,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)
}
}

0 comments on commit 16ae895

Please sign in to comment.