Repository navigation
Throw an error instead of crashing on an invalid @source glob - #20773
Open
RobinMalfait wants to merge 3 commits into
Open
RobinMalfait wants to merge 3 commits into
RobinMalfait wants to merge 3 commits into
Conversation
An `@source` pattern that is not a valid glob, like `@source not
"./src/**/*.{js"` with an unclosed `{`, reached
`GitignoreBuilder::add_line(…).unwrap()` in `create_walker`. The panic
aborted the whole Node process.
`create_walker` now returns the error, and the new `Scanner::try_new`
passes it on. The napi constructor uses `try_new`, so `new Scanner(…)`
throws a JS error that names the pattern:
The `@source` pattern `/path/to/project/src/**/*.{js` is not a valid
glob: unclosed alternate group; missing '}' (maybe escape '{' with
'[{]'?)
Each gitignore rule keeps the pattern of the source it comes from, so
the error names the `@source` pattern and not the rule (e.g. `!*.{js`).
Only patterns that crashed before get an error. Patterns that the
gitignore rules accept keep working as before.
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.
Summary
An
@sourcepattern that is not a valid glob crashed the whole Node.js process:The scanner turns each
@sourceinto a gitignore rule, andcreate_walkercompiled these rules withGitignoreBuilder::add_line(…).unwrap(). When the brace expansion of a pattern fails, the scanner keeps the raw pattern, so an invalid glob reaches thatunwrap(). The panic crossed the NAPI boundary, and the build tool died without a useful error.This happens for
@sourceand@source not, with:{, e.g../src/**/*.{js}without a{, e.g../src/a}./src/[z-a].html\, e.g../src/a\Now
create_walkerreturns the error, and the napi constructor ofScannerthrows it as a regular JavaScript error. The build fails with a message that names the pattern:The error names the pattern of the
@source, resolved against its base. It does not name the gitignore rule, which can differ (e.g.@source "./src/**/*.{js"becomes the rule!*.{js). The CSS file of the@sourceis not known in the scanner, so the message does not include it.Only patterns that crashed before throw an error now. Patterns that the gitignore rules accept keep their behavior. For example,
@source "./src/**/a}.js"still scans a file nameda}.js, because only the!*.jsrule reaches the gitignore builder.In Rust,
Scanner::try_newreturns the error.Scanner::newkeeps its signature and panics with the same message, for the existing Rust callers (the tests).This does not overlap with #20759, which changes
scanFilesandgetCandidatesWithPositions. This PR only changes the constructor.Test plan
it_should_error_on_invalid_source_globstocrates/oxide/tests/scanner.rs. It checks the error for each case above, for negated and positive patterns. Without the fix, each case panics atcrates/oxide/src/scanner/mod.rs:843.packages/@tailwindcss-postcss/src/index.test.tswith@source not "./src/**/*.{js": the build now rejects with the error. Without the fix, the test worker died withWorker exited unexpectedly.cargo test --workspacepnpm run build,pnpm run lintandvitest run(6128 tests pass)