Skip to content

Report more informative CSS errors#16752

Merged
bors-servo merged 4 commits intoservo:masterfrom
jdm:css-parse-error
Jun 9, 2017
Merged

Report more informative CSS errors#16752
bors-servo merged 4 commits intoservo:masterfrom
jdm:css-parse-error

Conversation

@jdm
Copy link
Copy Markdown
Member

@jdm jdm commented May 6, 2017

This requires servo/rust-cssparser#143 for the final commit. There's no better way to split that work up, unfortunately, and it's extremely easy to bitrot. I would appreciate if we could expedite reviewing this work.

This is the work necessary to enable https://bugzilla.mozilla.org/show_bug.cgi?id=1352669. It makes sense to merge it separately because it's so much effort to keep it up to date with the ongoing Stylo work.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes

This change is Reviewable

@jdm jdm added the S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. label May 6, 2017
@highfive highfive assigned ghost May 6, 2017
@highfive
Copy link
Copy Markdown

highfive commented May 6, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/shorthand/inherited_svg.mako.rs, components/style/values/specified/calc.rs, components/style/values/specified/color.rs, components/style/properties/longhand/background.mako.rs, components/style/properties/longhand/text.mako.rs and 61 more
  • @KiChjang: components/script/dom/element.rs, components/script/dom/node.rs, components/script_layout_interface/reporter.rs
  • @fitzgen: components/script/dom/element.rs, components/script/dom/node.rs, components/script_layout_interface/reporter.rs
  • @emilio: components/style/properties/shorthand/inherited_svg.mako.rs, components/style/values/specified/calc.rs, components/style/values/specified/color.rs, components/style/properties/longhand/background.mako.rs, components/style/properties/longhand/text.mako.rs and 62 more

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 6, 2017
@highfive
Copy link
Copy Markdown

highfive commented May 6, 2017

warning Warning warning

  • These commits modify style and script code, but no tests are modified. Please consider adding a test!

#[cfg(feature = "gecko")]
pub fn create_error_reporter() -> RustLogReporter {
RustLogReporter
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aren't both of them the exact same function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. That changes in my patches to Gecko.

@ghost
Copy link
Copy Markdown

ghost commented May 6, 2017

cc @servo/style

Copy link
Copy Markdown
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.

Wow, that's a big diff. Haven't gone through it with detail, would love help from @nox/@SimonSapin reviewing.

Some questions below.

line_offset,
location.column,
message)
error.to_string())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps we should implement Display for ContextualParseError? Fine as a followup I guess.

pub enum SelectorParseError<T> {
PseudoElementInComplexSelector,
NoQualifiedNameInAttributeSelector,
TooManyCompoundSelectorComponents,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's rename this to TooManyCompoundSelectorComponentsInNegation, or perhaps TooComplexNegationSelector?


impl<'a> ContextualParseError<'a> {
/// Turn a parse error into a string representation.
pub fn to_string(&self) -> String {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps we should implement Display and implement to_string as format!("{}", self)? Fine also as a followup/easy issue I guess :)

let result: Result<_, ParseError> = input.try(|input| {
match input.expect_ident() {
Ok(ident) => {
(match_ignore_ascii_case! { &ident,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it shouldn't be needed to wrap it in parenthesis anymore?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixing this will be kind of annoying given how often this pattern appears. I would prefer not to, if that's alright.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, that's totally fine for me :)

if let Ok(l) = input.try(|i| L::parse(context, i)) {
if pos.is_some() {
return Err(())
return Err(StyleParseError::UnspecifiedError.into())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an intention to convert all the UnspecifiedErrors into more explicit error kinds as followup work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. It's a nice source of easy issues and a lot of effort for this patch in particular.

_ => true
};
if !valid {
return Err(BasicParseError::UnexpectedToken(Token::Ident(ident)).into());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps just use braces in the upper match branch and get rid of valid?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nvm about this one.

"stretch" => Ok(ALIGN_STRETCH),
_ => Err(())
}
}).map_err(|()| BasicParseError::UnexpectedToken(Token::Ident(ident)).into())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm assuming this funky way of doing this is because ident is borrowed in the match expression, is that right? If so, that's kind of unfortunate, I guess... :(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep! Best compromise I could find.

Ok(ref s) if s.eq_ignore_ascii_case("inset") =>
input.parse_nested_block(|i| GenericInsetRect::parse_function_arguments(context, i)),
_ => Err(())
_ => Err(BasicParseError::ExpectedToken(Token::Function("inset".into())).into())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you know if this "inset".into() will allocate or not? I'm assuming that since it's an static string it shouldn't need to, but I worry that perhaps to coerce it to do that you may need to be explicit about it. Not a big deal in any case I think

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It should be a Cow::Borrowed afaik.

@bors-servo
Copy link
Copy Markdown
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label May 6, 2017
@SimonSapin
Copy link
Copy Markdown
Member

Reviewed 9 of 9 files at r1, 4 of 4 files at r2, 1 of 1 files at r3, 75 of 75 files at r4.
Review status: all files reviewed at latest revision, 11 unresolved discussions, some commit checks failed.


components/style/custom_properties.rs, line 241 at r4 (raw file):

                return Err(StyleParseError::CloseSquareBracketInDeclarationValueBlock.into()),
            Token::CloseCurlyBracket =>
                return Err(StyleParseError::CloseCurlyBracketInDeclarationValueBlock.into()),

These are not just (various kinds of) closing brackets, they are unbalanced / improperly nested ones.


components/style/media_queries.rs, line 227 at r4 (raw file):

            Ok(ident) => {
                let result: Result<_, ParseError> = MediaQueryType::parse(&*ident)
                    .map_err(|()| BasicParseError::UnexpectedToken(Token::Ident(ident)).into());

Could you avoid creating tokens like this? I have plans to change the Token data structure (to avoid more memory allocations) that involve structs with private fields, so that only the tokenizer will be able to create tokens. Maybe add a UnexpectedIdent error variant instead?


Comments from Reviewable

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. labels May 19, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jun 7, 2017
@jdm
Copy link
Copy Markdown
Member Author

jdm commented Jun 7, 2017

@SimonSapin I have addressed the review comments and made a new commit which applies to the existing code that you reviewed. I'm going to go ahead and rebase all of my changes separately now, and I won't push them until you are done reviewing the existing code.

@SimonSapin
Copy link
Copy Markdown
Member

r+


Reviewed 54 of 54 files at r5.
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


components/style/values/specified/basic_shape.rs, line 131 at r4 (raw file):

Previously, jdm (Josh Matthews) wrote…

It should be a Cow::Borrowed afaik.

Indeed, this uses Cow::Borrowed and does not allocate.


Comments from Reviewable

@jdm jdm force-pushed the css-parse-error branch from 6c3f4e4 to f9018ab Compare June 9, 2017 17:13
@jdm jdm force-pushed the css-parse-error branch 2 times, most recently from bedea39 to 98d0fb2 Compare June 9, 2017 19:25
@jdm
Copy link
Copy Markdown
Member Author

jdm commented Jun 9, 2017

@bors-servo: try

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Trying commit 98d0fb2 with merge d6288b9...

bors-servo pushed a commit that referenced this pull request Jun 9, 2017
Report more informative CSS errors

This requires servo/rust-cssparser#143 for the final commit. There's no better way to split that work up, unfortunately, and it's extremely easy to bitrot. I would appreciate if we could expedite reviewing this work.

This is the work necessary to enable https://bugzilla.mozilla.org/show_bug.cgi?id=1352669. It makes sense to merge it separately because it's so much effort to keep it up to date with the ongoing Stylo work.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16752)
<!-- Reviewable:end -->
@jdm jdm removed the S-needs-rebase There are merge conflict errors. label Jun 9, 2017
@bors-servo
Copy link
Copy Markdown
Contributor

💔 Test failed - windows-msvc-dev

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jun 9, 2017
@jdm jdm force-pushed the css-parse-error branch from 98d0fb2 to aceffc5 Compare June 9, 2017 20:24
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Jun 9, 2017
bors-servo pushed a commit to servo/rust-cssparser that referenced this pull request Jun 9, 2017
Return meaningful error values when parsing

This is #143 with an extra commit added to accommodate changes requested in servo/servo#16752.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/155)
<!-- Reviewable:end -->
@jdm jdm force-pushed the css-parse-error branch from aceffc5 to 27ae1ef Compare June 9, 2017 20:46
@jdm
Copy link
Copy Markdown
Member Author

jdm commented Jun 9, 2017

@bors-servo: r=SimonSapin

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit 27ae1ef has been approved by SimonSapin

@highfive highfive assigned SimonSapin and unassigned ghost Jun 9, 2017
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jun 9, 2017
@jdm
Copy link
Copy Markdown
Member Author

jdm commented Jun 9, 2017

@bors-servo: p=1

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit 27ae1ef with merge 061cb5f...

bors-servo pushed a commit that referenced this pull request Jun 9, 2017
Report more informative CSS errors

This requires servo/rust-cssparser#143 for the final commit. There's no better way to split that work up, unfortunately, and it's extremely easy to bitrot. I would appreciate if we could expedite reviewing this work.

This is the work necessary to enable https://bugzilla.mozilla.org/show_bug.cgi?id=1352669. It makes sense to merge it separately because it's so much effort to keep it up to date with the ongoing Stylo work.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16752)
<!-- Reviewable:end -->
@bors-servo
Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: SimonSapin
Pushing 061cb5f to master...

@bors-servo bors-servo mentioned this pull request Jun 9, 2017
5 tasks
@bors-servo bors-servo merged commit 27ae1ef into servo:master Jun 9, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 9, 2017
@nox
Copy link
Copy Markdown
Contributor

nox commented Jun 10, 2017

@jdm What was the problem with not sharing the same ParseError across all impls again?

let horizontal = try!(horizontal);
let vertical = input.try(RepeatKeyword::parse).ok();
Ok(SpecifiedValue::Other(horizontal, vertical))
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jdm Why was that change needed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh yeah borrowing issues, unfortunate. :(

@jdm
Copy link
Copy Markdown
Member Author

jdm commented Jun 11, 2017

@nox I'm not sure I understand the question. If it is why rust-cssparser's ParseError does not contain every possible error, the answer is because that's really inconvenient API design.

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.

6 participants