Skip to content

Commit 6cf732e

Browse files
committed
Make unwrap print helpful messages
1 parent 528d34b commit 6cf732e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ pub struct Library {
104104
}
105105

106106
/// Represents all reasons `pkg-config` might not succeed or be run at all.
107-
#[derive(Debug)]
108107
pub enum Error {
109108
/// Aborted because of `*_NO_PKG_CONFIG` environment variable.
110109
///
@@ -135,6 +134,13 @@ pub enum Error {
135134

136135
impl error::Error for Error {}
137136

137+
impl fmt::Debug for Error {
138+
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
139+
// Failed `unwrap()` prints Debug representation, but the default debug format lacks helpful instructions for the end users
140+
<Error as fmt::Display>::fmt(self, f)
141+
}
142+
}
143+
138144
impl fmt::Display for Error {
139145
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
140146
match *self {

0 commit comments

Comments
 (0)