Skip to content

Continuation PR for #256: Implement std::error::Error for errors #262

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
wants to merge 10 commits into from

Conversation

dutchmartin
Copy link

@dutchmartin dutchmartin commented Oct 19, 2019

This PR is the continuation of #256.
Some changes are due to me running cargo fmt
I have implemented description, but I can not satisfy the borrow checker with a reference of a String that will get deleted after the function ends. (see image). Therefore I used a static string pointing the user in the right direction.

Closes #256
Fixes #247

@nox
Copy link
Contributor

nox commented Oct 21, 2019

I have not implemented description because it is deprecated and i can not satisfy the borrow checker with a reference of a String that will get deleted after the function ends. (see image)

Please implement description as I already asked in #256.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #259) made this pull request unmergeable. Please resolve the merge conflicts.

@dutchmartin
Copy link
Author

dutchmartin commented Oct 22, 2019

I have not implemented description because it is deprecated and i can not satisfy the borrow checker with a reference of a String that will get deleted after the function ends. (see image)

Please implement description as I already asked in #256.

@nox
Done, please let me know what you think about the proposed solution.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #264) made this pull request unmergeable. Please resolve the merge conflicts.

@dutchmartin
Copy link
Author

@nox @SimonSapin Does one of you have time to review this?

}
}
}
($proc_macro_name: ident ! $paren: tt) => {
Copy link
Member

Choose a reason for hiding this comment

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

This seems a rustfmt bug that should be fixed and undone.

src/tokenizer.rs Outdated
),
QuotedString(value) => format!("The value '{}' does not include the quotes", value),
UnquotedUrl(value) => format!(
"The value '{}' does not include the `url(` `)` markers.",
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look right... UnquotedUrl is just url(string-without-quotes), not any kind of error.

src/tokenizer.rs Outdated
"The value '{}' does not include the `#` marker, but has a valid ID selector",
value
),
QuotedString(value) => format!("The value '{}' does not include the quotes", value),
Copy link
Member

Choose a reason for hiding this comment

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

Same for this, I don't know what this is about?

src/parser.rs Outdated
fn description(&self) -> String {
match self {
BasicParseErrorKind::UnexpectedToken(token) => {
format!("Unexpected token: '{}'", token.description())
Copy link
Member

Choose a reason for hiding this comment

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

I would just do: format!("Unexpected token: {:?}", token), and remove Token::description().

src/tokenizer.rs Outdated
SubstringMatch => String::from("*="),
CDO => String::from("<!--"),
CDC => String::from("-->"),
Function(name) => format!("The value ({}) does not include the `(` marker", name),
Copy link
Member

Choose a reason for hiding this comment

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

To be clear, these are legit token types. If the input is foo() and I do input.expect_ident(), I get an unexpected token error with the function, but there's nothing the "doesn't include the ( marker" or anything like that.

@dutchmartin dutchmartin requested a review from emilio April 27, 2020 15:25
@jdm
Copy link
Member

jdm commented May 6, 2020

Want to review the new commit @emilio?

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good! I think we should remove BasicParseErrorKind::description and implement Display instead, wdyt?

@@ -53,6 +55,20 @@ pub enum BasicParseErrorKind<'i> {
QualifiedRuleInvalid,
}

impl<'i> BasicParseErrorKind<'i> {
fn description(&self) -> String {
match self {
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to Display::fmt?

Choose a reason for hiding this comment

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

Addressed in the last commit

src/parser.rs Outdated
@@ -62,6 +78,18 @@ pub struct BasicParseError<'i> {
pub location: SourceLocation,
}

impl<'i> fmt::Display for BasicParseError<'i> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.kind.description().as_str())
Copy link
Member

Choose a reason for hiding this comment

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

That way this doesn't need the extra allocation.

Copy link
Member

Choose a reason for hiding this comment

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

Also, it may be nice to expose self.location, but that may be fine as a follow-up.

Choose a reason for hiding this comment

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

Done in c962d4a

src/parser.rs Outdated
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match &self.kind {
ParseErrorKind::Basic(basic_kind) => formatter.write_str(&basic_kind.description()),
Copy link
Member

Choose a reason for hiding this comment

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

This can just use basic_kind.fmt(formatter)

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #288) made this pull request unmergeable. Please resolve the merge conflicts.

@categulario
Copy link

Is there a way I can help with this?

@dutchmartin
Copy link
Author

@categulario If you would like to review and or make changes, please do. I wanted to finish this, but did not manage to. You have push access to my fork.
BTW: the concerns addressed by @emilio are reasonable.

@categulario
Copy link

Thanks @dutchmartin . I addressed @emilio 's concerns in c962d4a .

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #332) made this pull request unmergeable. Please resolve the merge conflicts.

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
7 participants