-
Notifications
You must be signed in to change notification settings - Fork 136
Implement std::error::Error for errors #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fbf6e37
to
ff679e1
Compare
} | ||
} | ||
|
||
impl<'i> Error for BasicParseError<'i> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you not implement description
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for Error
says: "This method is soft-deprecated. Although using it won’t cause compilation warning, new code should use Display instead and new impls can omit it."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement it anyway, calling BasicParseErrorKind::description
.
@SimonSapin @nox Could someone take another look at this PR? |
} | ||
} | ||
|
||
impl<'i> Error for BasicParseError<'i> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement it anyway, calling BasicParseErrorKind::description
.
@@ -62,6 +76,14 @@ pub struct BasicParseError<'i> { | |||
pub location: SourceLocation, | |||
} | |||
|
|||
impl<'i> fmt::Display for BasicParseError<'i> { | |||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | |||
write!(formatter, "{}", self.kind.description()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't print enough information, i.e. we end up not printing the payloads of UnexpectedToken(_)
and AtRuleInvalid(_)
.
write!(formatter, "{}", match &self.kind { | ||
ParseErrorKind::Basic(basic_kind) => basic_kind.description(), | ||
ParseErrorKind::Custom(_) => "Custom error", | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put the match outside and avoid write!
.
match &self.kind {
ParseErrorKind::Basic(basic) => basic.fmt(formatter),
ParseErrorKind::Custom(_) => "custom error".fmt(formatter),
}
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
write!(formatter, "{}", match &self.kind { | ||
ParseErrorKind::Basic(basic_kind) => basic_kind.description(), | ||
ParseErrorKind::Custom(_) => "Custom error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the payload disregarded here?
} | ||
} | ||
|
||
impl<'i, T> Error for ParseError<'i, T> where T: fmt::Debug {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement description
here.
This change is
Fixes #247.