Skip to content

Conversation

@willstranton
Copy link
Contributor

You can now set the --downloader_config flag multiple times to specify several downloader config files at once.

Fixes #13131


An initial refactoring was done to clean up unused arguments in UrlRewriter.

UrlRewriter does not used the passed in log arguement in its contructor.  This should have been cleaned up as part of bazelbuild@d21345d

This also cleans up some other routing to provide that logger.
You can now set the `--downloader_config` flag multiple times to specify
several downloader config files at once.

Fixes bazelbuild#13131
@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 Dec 5, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @willstranton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the flexibility of the downloader configuration by enabling the use of multiple configuration files. This allows for more modular and layered URL rewriting and blocking rules, addressing a long-standing issue and streamlining the setup for complex download scenarios. The underlying code has been updated to gracefully handle these multiple inputs.

Highlights

  • Multiple Downloader Configs: The --downloader_config flag can now be specified multiple times, allowing users to provide several downloader configuration files simultaneously.
  • UrlRewriter Refactoring: The UrlRewriter class has been refactored to support processing multiple configuration files and to remove unused arguments, improving code cleanliness and maintainability.
  • Issue Fix: This change addresses and fixes issue Support several downloader configs #13131.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for specifying multiple downloader configuration files by allowing the --downloader_config flag to be used multiple times. The implementation correctly handles parsing multiple configuration files and aggregating their rules. The refactoring to remove unused arguments from UrlRewriter also improves code clarity.

My review includes two high-severity findings in UrlRewriter.java:

  1. A potential NullPointerException when resolving config paths if Bazel is run outside a workspace.
  2. An incorrect error handling pattern when using com.google.common.io.Closer, which could obscure the root cause of file I/O errors.

I've provided suggestions to fix both issues. Otherwise, the changes look good and well-tested.

Comment on lines 95 to 97
public static UrlRewriter getDownloaderUrlRewriter(
Path workspaceRoot, @Nullable PathFragment configPath, Reporter reporter)
Path workspaceRoot, @Nullable List<PathFragment> configPaths)
throws UrlRewriterParseException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

workspaceRoot can be null if Bazel is run outside a workspace. However, on line 106, workspaceRoot.getRelative(...) is called without a null check, which will cause a NullPointerException if configPaths is not empty.

You should add a check to handle this case. For example, you could throw an exception if workspaceRoot is null and configPaths is not empty, as relative paths for downloader configs cannot be resolved without a workspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the existing code. I'll leave this as is.

Comment on lines 133 to 135
} catch (Throwable e) {
throw closer.rethrow(new UrlRewriterParseException(e.getMessage()));
} finally {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of closer.rethrow here is incorrect. It wraps the new UrlRewriterParseException in a RuntimeException, which is not what the method signature indicates. It also loses the original exception's stack trace, making debugging harder. The original exception should be rethrown so it can be caught by the outer catch block.

This will rethrow IOExceptions from getInputStream, which will then be caught by the outer catch block on line 138 and wrapped in a UrlRewriterParseException, preserving the cause. This is the standard pattern for using Closer.

Suggested change
} catch (Throwable e) {
throw closer.rethrow(new UrlRewriterParseException(e.getMessage()));
} finally {
} catch (Throwable e) {
throw closer.rethrow(e);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - you're right. This should just rethrow. Updated in the latest commit.


@VisibleForTesting
UrlRewriter(Consumer<String> log, String filePathForErrorReporting, Reader reader)
UrlRewriter(String filePathForErrorReporting, Reader reader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still need this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't needed. I didn't want to update all the tests and left this convenience constructor.

It is now removed in the latest commit pushed. I also removed an unneeded instance variable as well. Please take a look.

The single file and reader constructor of UrlRewriter is removed in favor of the more general multiple file/reader constructor.

The `rewriter` instance variable is also removed since it is always assigned to the same value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support several downloader configs

2 participants