Skip to content
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

Report more informative CSS errors #16752

Merged
merged 4 commits into from Jun 9, 2017
Merged

Report more informative CSS errors #16752

merged 4 commits into from Jun 9, 2017

Conversation

@jdm
Copy link
Member

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

@highfive
Copy link

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

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
}

This comment has been minimized.

@nox

nox May 6, 2017

Member

Aren't both of them the exact same function?

This comment has been minimized.

@jdm

jdm May 6, 2017

Author Member

Yes. That changes in my patches to Gecko.

@wafflespeanut
Copy link
Member

wafflespeanut commented May 6, 2017

Copy link
Member

emilio left a comment

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

Some questions below.

let location = input.source_location(position);
let line_offset = location.line + line_number_offset as usize;
if log_enabled!(log::LogLevel::Info) {
info!("Url:\t{}\n{}:{} {}",
url.as_str(),
line_offset,
location.column,
message)
error.to_string())

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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

pub enum SelectorParseError<T> {
PseudoElementInComplexSelector,
NoQualifiedNameInAttributeSelector,
TooManyCompoundSelectorComponents,

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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 {

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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,

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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

This comment has been minimized.

@jdm

jdm May 7, 2017

Author Member

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

This comment has been minimized.

@emilio

emilio May 7, 2017

Member

Yeah, that's totally fine for me :)

where F: FnMut(Keyword) -> bool
{
let (mut pos, mut keyword) = (None, None);
for _ in 0..2 {
if let Ok(l) = input.try(|i| L::parse(context, i)) {
if pos.is_some() {
return Err(())
return Err(StyleParseError::UnspecifiedError.into())

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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

This comment has been minimized.

@jdm

jdm May 6, 2017

Author Member

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

};
if !valid {
return Err(BasicParseError::UnexpectedToken(Token::Ident(ident)).into());

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

nvm about this one.

"auto" => Ok(ALIGN_AUTO),
"normal" => Ok(ALIGN_NORMAL),
"stretch" => Ok(ALIGN_STRETCH),
_ => Err(())
}
}).map_err(|()| BasicParseError::UnexpectedToken(Token::Ident(ident)).into())

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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... :(

This comment has been minimized.

@jdm

jdm May 6, 2017

Author Member

Yep! Best compromise I could find.

match input.try(|i| i.expect_function()) {
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())

This comment has been minimized.

@emilio

emilio May 6, 2017

Member

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

This comment has been minimized.

@jdm

jdm May 6, 2017

Author Member

It should be a Cow::Borrowed afaik.

@bors-servo
Copy link
Contributor

bors-servo commented May 6, 2017

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

@SimonSapin
Copy link
Member

SimonSapin commented May 19, 2017

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
Copy link
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
Member

SimonSapin commented Jun 7, 2017

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 jdm:css-parse-error branch from 6c3f4e4 to f9018ab Jun 9, 2017
@jdm jdm force-pushed the jdm:css-parse-error branch 2 times, most recently from bedea39 to 98d0fb2 Jun 9, 2017
@jdm
Copy link
Member Author

jdm commented Jun 9, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jun 9, 2017

Trying commit 98d0fb2 with merge d6288b9...

bors-servo added 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 label Jun 9, 2017
@bors-servo
Copy link
Contributor

bors-servo commented Jun 9, 2017

💔 Test failed - windows-msvc-dev

@jdm jdm force-pushed the jdm:css-parse-error branch from 98d0fb2 to aceffc5 Jun 9, 2017
@highfive highfive removed the S-tests-failed label Jun 9, 2017
bors-servo added 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 jdm:css-parse-error branch from aceffc5 to 27ae1ef Jun 9, 2017
@jdm
Copy link
Member Author

jdm commented Jun 9, 2017

@bors-servo: r=SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Jun 9, 2017

📌 Commit 27ae1ef has been approved by SimonSapin

@jdm
Copy link
Member Author

jdm commented Jun 9, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jun 9, 2017

Testing commit 27ae1ef with merge 061cb5f...

bors-servo added 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
Contributor

bors-servo commented Jun 9, 2017

@bors-servo bors-servo mentioned this pull request Jun 9, 2017
3 of 5 tasks complete
@bors-servo bors-servo merged commit 27ae1ef into servo:master Jun 9, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@nox
Copy link
Member

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))
})

This comment has been minimized.

@nox

nox Jun 10, 2017

Member

@jdm Why was that change needed?

This comment has been minimized.

@nox

nox Jun 10, 2017

Member

Oh yeah borrowing issues, unfortunate. :(

@jdm
Copy link
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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.