Skip to content

Report Bazel incompatibilities even with syntax and eval errors#28364

Open
fmeum wants to merge 13 commits intobazelbuild:masterfrom
fmeum:28350-bazel-compatibility
Open

Report Bazel incompatibilities even with syntax and eval errors#28364
fmeum wants to merge 13 commits intobazelbuild:masterfrom
fmeum:28350-bazel-compatibility

Conversation

@fmeum
Copy link
Collaborator

@fmeum fmeum commented Jan 21, 2026

This ensures that users see a helpful error message pointing out that their Bazel version isn't compatible with a particular module even if the MODULE.bazel file contains constructs unsupported by that version of Bazel. This also extends to the bazel_compatibility syntax itself.

The implementation achieves this by:

  • Retrying to compile the MODULE.bazel file up to the module() call if syntax errors are encountered. These errors are stored and only emitted after the Bazel compatibility constraints of the truncated file have been obtained and evaluated.
  • Making extra keyword args on module() a lazy error in the same way.
  • Catching EvalExceptions thrown after the module() call and emitting the incompatibility information.
  • Allowing invalid (from the point of view of the current Bazel version) compatibility constraints after a first one that's valid and incompatible.

Fixes #28350

public void throwDelayedExceptionIfAny(
@Nullable EvalException evalException, ExtendedEventHandler eventHandler)
throws EvalException {
if (incompatibilityMessage != null && (delayedSyntaxError != null || evalException != null)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't ideal yet: I think that the UX would be better if we did emit the original eval/syntax error, but augmented with the note that the current module isn't compatible with the current Bazel version. What do you think?

@fmeum fmeum marked this pull request as ready for review January 21, 2026 18:16
@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 Jan 21, 2026
@fmeum
Copy link
Collaborator Author

fmeum commented Jan 21, 2026

@Wyverald This can likely be cleaned up more, but I wanted to run this by you first since it's a bit of an unusual change. :-)

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 significantly enhances the user experience by improving error reporting for Bazel incompatibilities in MODULE.bazel files. The refactoring of the BazelVersion class centralizes compatibility logic, and the new error handling mechanism intelligently prioritizes and reports relevant incompatibility messages even when syntax or evaluation errors are present. The changes are well-implemented and directly address the goal of providing more helpful feedback to users.

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.

MODULE.bazel: bazel_compatibility constraint breaks when a module dep has invalid syntax for current bazel

1 participant