apply: take the parsed stylesheet, not the CSS text - #287
Merged
Conversation
samoht
force-pushed
the
apply-error-propagation
branch
from
August 2, 2026 04:57
ba76bde to
f40a4dd
Compare
samoht
force-pushed
the
apply-error-propagation
branch
from
August 2, 2026 05:33
f40a4dd to
7a17fa9
Compare
samoht
force-pushed
the
apply-error-propagation
branch
from
August 2, 2026 05:45
7a17fa9 to
14804c2
Compare
samoht
force-pushed
the
apply-error-propagation
branch
from
August 2, 2026 05:59
14804c2 to
f02301c
Compare
A <style> block the parser cannot use is deleted from the page and the command exits 0, so a redirect ships an unstyled page under a green status; an extra stylesheet that does not parse, or cannot be read at all, is the same shape at the CLI. The rule count reported alongside is a count of statements, so a @media block holding three rules reports one.
compute parsed the CSS itself and answered an empty result when the parse failed, so a caller had no way to tell a stylesheet that did not parse from one that was empty - both projected onto nothing. Taking a parsed sheet leaves the parse, and the warnings Css.of_string collects for an input it had to recover, with the caller. The CLI keeps its current behaviour for now.
Every <style> block was concatenated into one string, parsed once, and deleted from the page whatever came back, so a block the parser could not use left the page unstyled under a green exit status. Each block now parses on its own - as a browser reads them - and one that parses to nothing stays where it is, reported and gated by an exit 1 the way cascade fmt gates a stylesheet recovery emptied. A supplementary stylesheet that cannot be read at all is an error too: cmdliner checks that the path exists, not that it can be read.
The interface calls kept a count of rules and the CLI reports it as one, but a block at-rule counted once for its wrapper, so a @media holding three rules said one. The descent goes through Stylesheet.statement_children, whose match is exhaustive; an at-rule with no statements of its own is itself the one thing kept and still counts once.
samoht
force-pushed
the
apply-error-propagation
branch
from
August 2, 2026 06:02
f02301c to
74e8f41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cascade apply deleted a <style> block it could not parse (page shipped unstyled, exit 0) and treated an unreadable supplementary stylesheet as no CSS at all. The root cause is that Css.of_string returns Ok with warnings and an empty sheet for garbage, so no result type on compute could see it: Apply.Make(_).compute now takes ~sheet:Stylesheet.t and the parse stays with the caller (breaking, in CHANGES). The CLI keeps an unusable block verbatim and exits 1, mirroring fmt's #273 contract; style blocks now parse independently as a browser reads them; and result.kept counts rules, not wrapper statements. Stacked on #286.