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

stylo: Error reporting for unknown media features #18341

Merged
merged 1 commit into from
Sep 8, 2017

Conversation

ferjm
Copy link
Contributor

@ferjm ferjm commented Sep 1, 2017

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix bug 1384225

This change is Reviewable

@highfive
Copy link

highfive commented Sep 1, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/error_reporting.rs, components/style/media_queries.rs, components/style/stylesheets/rule_parser.rs
  • @canaltinova: components/style/error_reporting.rs, components/style/media_queries.rs, components/style/stylesheets/rule_parser.rs
  • @KiChjang: components/script/dom/htmllinkelement.rs, components/script/dom/cssmediarule.rs, components/script/dom/medialist.rs, components/script/dom/htmlstyleelement.rs, components/script/dom/window.rs
  • @fitzgen: components/script/dom/htmllinkelement.rs, components/script/dom/cssmediarule.rs, components/script/dom/medialist.rs, components/script/dom/htmlstyleelement.rs, components/script/dom/window.rs
  • @emilio: ports/geckolib/glue.rs, components/style/error_reporting.rs, components/style/media_queries.rs, components/style/stylesheets/rule_parser.rs, ports/geckolib/error_reporter.rs

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

highfive commented Sep 1, 2017

warning Warning warning

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

@ferjm
Copy link
Contributor Author

ferjm commented Sep 1, 2017

r? @jdm I believe you wrote most part of css error reporting.

@highfive highfive assigned jdm and unassigned KiChjang Sep 1, 2017
@@ -240,19 +241,29 @@ impl MediaQuery {
/// media query list is only filled with the equivalent of "not all", see:
///
/// https://drafts.csswg.org/mediaqueries/#error-handling
pub fn parse_media_query_list(context: &ParserContext, input: &mut Parser) -> MediaList {
pub fn parse_media_query_list<R>(context: &ParserContext,
Copy link
Member

Choose a reason for hiding this comment

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

Let's format this as rustfmt would:

pub fn parse_media_query_list<R>(
    context: &ParserContext,
    input: &mut Parser,
    error_reporter: &R,
) -> MediaList
where
    R: ParseErrorReporter,
{

media_queries.push(MediaQuery::never_matching());
let error = ContextualParseError::InvalidMediaFeature(
Copy link
Member

Choose a reason for hiding this comment

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

So this would report Expected media feature name but found..., but there are definitely more errors than can happen instead... What does gecko do for those? Does it report them? I suspect not.

Copy link
Member

Choose a reason for hiding this comment

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

Yes; we will want to add a new variant to StyleParseError that is only returned when an invalid media feature is encountered, and only report if that variant is encountered here.

@jdm
Copy link
Member

jdm commented Sep 1, 2017

@ferjm ferjm closed this Sep 4, 2017
@ferjm ferjm reopened this Sep 4, 2017
@ferjm ferjm changed the title stylo: Error reporting for unknown media features [WIP] stylo: Error reporting for unknown media features Sep 4, 2017
@bors-servo
Copy link
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Sep 4, 2017
@ferjm ferjm changed the title [WIP] stylo: Error reporting for unknown media features stylo: Error reporting for unknown media features Sep 5, 2017
@ferjm ferjm removed the S-needs-rebase There are merge conflict errors. label Sep 5, 2017
@ferjm
Copy link
Contributor Author

ferjm commented Sep 5, 2017

Feedback addressed and test added https://bugzilla.mozilla.org/show_bug.cgi?id=1384225#c5

CssParseError::Custom(SelectorParseError::Custom(
StyleParseError::MediaQueryExpectedFeatureValue)) =>
ContextualParseError::MediaQueryExpectedFeatureValue,
_ => ContextualParseError::UnknownAtRule(input.slice_from(start_position), err),
Copy link
Member

Choose a reason for hiding this comment

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

UnknownAtRule is not necessarily correct, is it? We can try to parse media query lists from a whole set of different places, like @import rules, stylesheet attributes...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right. I guess something like a new UnknownMediaQuery will do then?

Copy link
Member

Choose a reason for hiding this comment

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

Rather than matching on known errors here, we should simply have a InvalidMediaRule(ParseError) variant.

}
Err(()) => return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
},
Err(()) =>
Copy link
Member

Choose a reason for hiding this comment

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

nit: use a block here.

@emilio
Copy link
Member

emilio commented Sep 5, 2017

r? @jdm

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

Other testcase:
<style>@media "foo" {}</style> should yield Expected identifier in media list but found ‘"foo"’.
The use of RangedExpressionWithNoValue should also be an instance of MediaQueryExpectedFeatureValue, I believe. The use of UnexpectedIdent should be replaced by MediaQueryExpectedFeatureName instead.

@@ -564,7 +565,7 @@ impl Expression {
// for parity with gecko. We should remove this check when we want
// to support it.
if let Length::Calc(_) = length {
return Err(StyleParseError::UnspecifiedError.into())
return Err(StyleParseError::MediaQueryExpectedFeatureValue.into())
Copy link
Member

Choose a reason for hiding this comment

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

There a bunch of errors that can be returned in this feature value code that aren't caught (like let length = Length::parse_non_negative(context, input)?;). Let's extract all of this parsing code into a separate function and use map_err to translate any error that is returned into StyleParseError::MediaQueryExpectedFeatureValue instead.

CssParseError::Custom(SelectorParseError::Custom(
StyleParseError::MediaQueryExpectedFeatureValue)) =>
ContextualParseError::MediaQueryExpectedFeatureValue,
_ => ContextualParseError::UnknownAtRule(input.slice_from(start_position), err),
Copy link
Member

Choose a reason for hiding this comment

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

Rather than matching on known errors here, we should simply have a InvalidMediaRule(ParseError) variant.

ContextualParseError::MediaQueryExpectedFeatureValue =>
(b"PEMQExpectedFeatureValue\0", Action::Nothing),
ContextualParseError::MediaQueryNoMinMaxWithoutValue =>
(b"PEMQNoMinMaxWithoutValue\0", Action::Nothing),
Copy link
Member

Choose a reason for hiding this comment

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

These will look like:

ContextualPArseError::InvalidMediaQuery(
    CssParseError::Custom(SelectorParseError::Custom(StyleParseError::MediaQueryExpectedFeatureName(..)))) =>
    (b"PEMQExpectedFeatureName\0", Action::Nothing),

@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. labels Sep 5, 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 Sep 7, 2017
@ferjm
Copy link
Contributor Author

ferjm commented Sep 7, 2017

r? @jdm

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

Almost there! We can get better error messages by explicitly adding the token or identifier to the error variants, however.

Err(()) => return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
},
Err(()) => {
return Err(StyleParseError::MediaQueryExpectedFeatureName.into())
Copy link
Member

Choose a reason for hiding this comment

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

We should pass the ident that was not recognized as a parameter of this error variant.

input.parse_nested_block(|input| {
// FIXME: remove extra indented block when lifetimes are non-lexical
let feature;
let range;
{
let ident = input.expect_ident()?;
let ident = input.expect_ident().map_err(|_|
StyleParseError::MediaQueryExpectedFeatureName
Copy link
Member

Choose a reason for hiding this comment

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

This should be ExpectedIdentifier, instead. We can match an UnexpectedToken error, extract it and add it as a parameter of the error variant.

@@ -488,13 +570,17 @@ impl Expression {
/// ```
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
input.expect_parenthesis_block()?;
input.expect_parenthesis_block().map_err(|_|
Copy link
Member

Choose a reason for hiding this comment

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

Gecko does not report an error here, so we can revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I revert this, @media "foo" {} would only report "Declaration dropped" instead of "Expected identifier in media list but found ‘ "foo" ’"

@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. labels Sep 7, 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 Sep 8, 2017
@ferjm
Copy link
Contributor Author

ferjm commented Sep 8, 2017

r? @jdm

@jdm
Copy link
Member

jdm commented Sep 8, 2017

@bors-servo: r+
Thanks!

@bors-servo
Copy link
Contributor

📌 Commit 337a903 has been approved by jdm

@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 Sep 8, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 337a903 with merge fef2cfd...

bors-servo pushed a commit that referenced this pull request Sep 8, 2017
stylo: Error reporting for unknown media features

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix [bug 1384225](https://bugzilla.mozilla.org/show_bug.cgi?id=1384225)

<!-- 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/18341)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Sep 8, 2017
@ferjm
Copy link
Contributor Author

ferjm commented Sep 8, 2017

@bors-servo: retry

I think these are intermittents

@bors-servo
Copy link
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev are reusable. Rebuilding only linux-rel-css, linux-rel-wpt...

@bors-servo
Copy link
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: jdm
Pushing fef2cfd to master...

@bors-servo bors-servo merged commit 337a903 into servo:master Sep 8, 2017
@KiChjang
Copy link
Contributor

KiChjang commented Sep 8, 2017

@ferjm I'm not in front of a computer, could you please open new issues filing the intermittents you see here?

@jdm
Copy link
Member

jdm commented Sep 8, 2017

#18424 and #18273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-tests-failed The changes caused existing tests to fail.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants