Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Condense Error's Debug format in a way to include whole message
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 30, 2022
1 parent 26e67d8 commit e3aea3e
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/error.rs
Expand Up @@ -259,24 +259,23 @@ impl ErrorImpl {

fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ErrorImpl::Message(msg, pos) => f.debug_tuple("Message").field(msg).field(pos).finish(),
ErrorImpl::Libyaml(err) => f.debug_tuple("Libyaml").field(err).finish(),
ErrorImpl::Io(io) => f.debug_tuple("Io").field(io).finish(),
ErrorImpl::FromUtf8(from_utf8) => f.debug_tuple("FromUtf8").field(from_utf8).finish(),
ErrorImpl::EndOfStream => f.write_str("EndOfStream"),
ErrorImpl::MoreThanOneDocument => f.write_str("MoreThanOneDocument"),
ErrorImpl::RecursionLimitExceeded(mark) => {
f.debug_tuple("RecursionLimitExceeded").field(mark).finish()
}
ErrorImpl::RepetitionLimitExceeded => f.write_str("RepetitionLimitExceeded"),
ErrorImpl::BytesUnsupported => f.write_str("BytesUnsupported"),
ErrorImpl::UnknownAnchor(mark) => f.debug_tuple("UnknownAnchor").field(mark).finish(),
ErrorImpl::SerializeNestedEnum => f.write_str("SerializeNestedEnum"),
ErrorImpl::ScalarInMerge => f.write_str("ScalarInMerge"),
ErrorImpl::TaggedInMerge => f.write_str("TaggedInMerge"),
ErrorImpl::ScalarInMergeElement => f.write_str("ScalarInMergeElement"),
ErrorImpl::SequenceInMergeElement => f.write_str("SequenceInMergeElement"),
ErrorImpl::Libyaml(err) => Debug::fmt(err, f),
ErrorImpl::Shared(err) => err.debug(f),
_ => {
f.write_str("Error(")?;
struct MessageNoMark<'a>(&'a ErrorImpl);
impl<'a> Display for MessageNoMark<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.message_no_mark(f)
}
}
let msg = MessageNoMark(self).to_string();
Debug::fmt(&msg, f)?;
if let Some(mark) = self.mark() {
write!(f, ", line: {}, column: {}", mark.line(), mark.column())?;
}
f.write_str(")")
}
}
}
}

0 comments on commit e3aea3e

Please sign in to comment.