-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
Heads up! This PR modifies the following files:
|
r? @jdm I believe you wrote most part of css error reporting. |
components/style/media_queries.rs
Outdated
@@ -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, |
There was a problem hiding this comment.
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,
{
components/style/media_queries.rs
Outdated
media_queries.push(MediaQuery::never_matching()); | ||
let error = ContextualParseError::InvalidMediaFeature( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Can you add a new test to https://dxr.mozilla.org/mozilla-central/source/layout/style/test/test_css_parse_error_smoketest.html for this as well? |
3877856
to
bcddb19
Compare
ddf0033
to
5a8aa19
Compare
☔ The latest upstream changes (presumably #18355) made this pull request unmergeable. Please resolve the merge conflicts. |
5a8aa19
to
8c332c8
Compare
8c332c8
to
fd52218
Compare
Feedback addressed and test added https://bugzilla.mozilla.org/show_bug.cgi?id=1384225#c5 |
components/style/media_queries.rs
Outdated
CssParseError::Custom(SelectorParseError::Custom( | ||
StyleParseError::MediaQueryExpectedFeatureValue)) => | ||
ContextualParseError::MediaQueryExpectedFeatureValue, | ||
_ => ContextualParseError::UnknownAtRule(input.slice_from(start_position), err), |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(()) => |
There was a problem hiding this comment.
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.
r? @jdm |
There was a problem hiding this 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()) |
There was a problem hiding this comment.
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.
components/style/media_queries.rs
Outdated
CssParseError::Custom(SelectorParseError::Custom( | ||
StyleParseError::MediaQueryExpectedFeatureValue)) => | ||
ContextualParseError::MediaQueryExpectedFeatureValue, | ||
_ => ContextualParseError::UnknownAtRule(input.slice_from(start_position), err), |
There was a problem hiding this comment.
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.
ports/geckolib/error_reporter.rs
Outdated
ContextualParseError::MediaQueryExpectedFeatureValue => | ||
(b"PEMQExpectedFeatureValue\0", Action::Nothing), | ||
ContextualParseError::MediaQueryNoMinMaxWithoutValue => | ||
(b"PEMQNoMinMaxWithoutValue\0", Action::Nothing), |
There was a problem hiding this comment.
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),
fd52218
to
3533cfb
Compare
3533cfb
to
1fabc6e
Compare
1fabc6e
to
c709490
Compare
r? @jdm |
There was a problem hiding this 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()) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(|_| |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" ’"
c709490
to
337a903
Compare
r? @jdm |
@bors-servo: r+ |
📌 Commit 337a903 has been approved by |
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 -->
💔 Test failed - linux-rel-wpt |
@bors-servo: retry I think these are intermittents |
⚡ 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... |
☀️ 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 |
@ferjm I'm not in front of a computer, could you please open new issues filing the intermittents you see here? |
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsThis change is