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

fix(downloader): handle invalid regex in downloader config #25380

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ankush1oo8
Copy link

Description:

This pull request addresses Issue #20832, where an invalid regex in the --experimental_downloader_config file caused Bazel to crash silently without an error message.

Changes Introduced:

  • Added a try-catch block to catch PatternSyntaxException when compiling regex patterns in UrlRewriterConfig.java.
  • Throws a UrlRewriterParseException with a clear error message instead of crashing.
  • Includes details on the regex error, such as the invalid sequence and its index in the pattern.

Before the Fix:

  • An invalid regex in downloader.cfg (e.g., rewrite (.*\maven.org/.*) http://example.com/mirror/$1) caused Bazel to crash with error code 37, but no explanation was given.

After the Fix:

  • Users now see a clear error message pointing out the invalid regex and its exact issue:
    Invalid regex in `rewrite`: Illegal/unsupported escape sequence at index 4 in `(.*\maven.org/.*)`
    
  • This helps users quickly debug and fix their configuration.

Testing & Verification:

  • Manually tested by providing valid and invalid regex patterns in downloader.cfg.
  • Verified that valid patterns work correctly and invalid patterns produce a proper error message.

Impact & Notes:

  • No breaking changes.
  • Improves developer experience by preventing silent crashes and providing actionable feedback.

Related Issue:

Closes #20832

Copy link

google-cla bot commented Feb 25, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Feb 25, 2025
@sgowroji
Copy link
Member

Hi @Ankush1oo8, Could you please take a  look at the above failure

@sgowroji sgowroji added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels Feb 26, 2025
@Ankush1oo8
Copy link
Author

@sgowroji Can you help me in what should I do

@sgowroji
Copy link
Member

Check the error logs from the failure Buildkite logs https://buildkite.com/bazel/bazel-bazel-github-presubmit/builds/26162#01953eb4-3448-4b5e-87d1-5586237673e7

'''src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/UrlRewriterConfig.java:134: error: cannot find symbol
} catch (PatternSyntaxException e) {
^
symbol: class PatternSyntaxException
location: class UrlRewriterConfig
(20:04:00) INFO: Elapsed time: 18.833s, Critical Path: 6.93s
(20:04:00) INFO: 7723 processes: 6889 remote cache hit, 824 internal, 8 linux-sandbox, 2 local.
(20:04:00) ERROR: Build did NOT complete successfully'''

@Ankush1oo8
Copy link
Author

Check the error logs from the failure Buildkite logs https://buildkite.com/bazel/bazel-bazel-github-presubmit/builds/26162#01953eb4-3448-4b5e-87d1-5586237673e7

'''src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/UrlRewriterConfig.java:134: error: cannot find symbol } catch (PatternSyntaxException e) { ^ symbol: class PatternSyntaxException location: class UrlRewriterConfig (20:04:00) INFO: Elapsed time: 18.833s, Critical Path: 6.93s (20:04:00) INFO: 7723 processes: 6889 remote cache hit, 824 internal, 8 linux-sandbox, 2 local. (20:04:00) ERROR: Build did NOT complete successfully'''

Can you check now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-user-response Awaiting a response from the author team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid --experimental_downloader_config file crashes bazel without an error message
2 participants