Skip to content

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

Closed

Conversation

KamilaBorowska
Copy link

@KamilaBorowska KamilaBorowska commented Aug 9, 2019

This change is Reviewable

Fixes #247.

}
}

impl<'i> Error for BasicParseError<'i> {}
Copy link
Contributor

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?

Copy link
Author

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."

Copy link
Contributor

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.

@dutchmartin
Copy link

@SimonSapin @nox Could someone take another look at this PR?
If there are any issues with it, please let me know.
I am happy to fix them since I want to use this error feature in my own project.

}
}

impl<'i> Error for BasicParseError<'i> {}
Copy link
Contributor

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())
Copy link
Contributor

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(_).

Comment on lines +183 to +186
write!(formatter, "{}", match &self.kind {
ParseErrorKind::Basic(basic_kind) => basic_kind.description(),
ParseErrorKind::Custom(_) => "Custom error",
})
Copy link
Contributor

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",
Copy link
Contributor

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 {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement description here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PasrseError and error Trait
3 participants