Report more informative CSS errors#16752
Conversation
|
Heads up! This PR modifies the following files:
|
| #[cfg(feature = "gecko")] | ||
| pub fn create_error_reporter() -> RustLogReporter { | ||
| RustLogReporter | ||
| } |
There was a problem hiding this comment.
Aren't both of them the exact same function?
There was a problem hiding this comment.
Yes. That changes in my patches to Gecko.
|
cc @servo/style |
emilio
left a comment
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Perhaps we should implement Display for ContextualParseError? Fine as a followup I guess.
components/selectors/parser.rs
Outdated
| pub enum SelectorParseError<T> { | ||
| PseudoElementInComplexSelector, | ||
| NoQualifiedNameInAttributeSelector, | ||
| TooManyCompoundSelectorComponents, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
I think it shouldn't be needed to wrap it in parenthesis anymore?
There was a problem hiding this comment.
Fixing this will be kind of annoying given how often this pattern appears. I would prefer not to, if that's alright.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Is there an intention to convert all the UnspecifiedErrors into more explicit error kinds as followup work?
There was a problem hiding this comment.
Yes. It's a nice source of easy issues and a lot of effort for this patch in particular.
components/style/values/mod.rs
Outdated
| _ => true | ||
| }; | ||
| if !valid { | ||
| return Err(BasicParseError::UnexpectedToken(Token::Ident(ident)).into()); |
There was a problem hiding this comment.
Perhaps just use braces in the upper match branch and get rid of valid?
| "stretch" => Ok(ALIGN_STRETCH), | ||
| _ => Err(()) | ||
| } | ||
| }).map_err(|()| BasicParseError::UnexpectedToken(Token::Ident(ident)).into()) |
There was a problem hiding this comment.
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... :(
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
It should be a Cow::Borrowed afaik.
|
☔ The latest upstream changes (presumably #16754) made this pull request unmergeable. Please resolve the merge conflicts. |
|
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. components/style/custom_properties.rs, line 241 at r4 (raw file):
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):
Could you avoid creating tokens like this? I have plans to change the Comments from Reviewable |
|
@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. |
|
r+ Reviewed 54 of 54 files at r5. components/style/values/specified/basic_shape.rs, line 131 at r4 (raw file): Previously, jdm (Josh Matthews) wrote…
Indeed, this uses Comments from Reviewable |
bedea39 to
98d0fb2
Compare
|
@bors-servo: try |
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 -->
|
💔 Test failed - windows-msvc-dev |
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 -->
|
@bors-servo: r=SimonSapin |
|
📌 Commit 27ae1ef has been approved by |
|
@bors-servo: p=1 |
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 -->
|
☀️ 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 |
|
@jdm What was the problem with not sharing the same |
| let horizontal = try!(horizontal); | ||
| let vertical = input.try(RepeatKeyword::parse).ok(); | ||
| Ok(SpecifiedValue::Other(horizontal, vertical)) | ||
| }) |
There was a problem hiding this comment.
Oh yeah borrowing issues, unfortunate. :(
|
@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. |
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 -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is