Add causes parameter to fail and use it for extension tags#17889
Closed
fmeum wants to merge 3 commits intobazelbuild:masterfrom
Closed
Add causes parameter to fail and use it for extension tags#17889fmeum wants to merge 3 commits intobazelbuild:masterfrom
causes parameter to fail and use it for extension tags#17889fmeum wants to merge 3 commits intobazelbuild:masterfrom
Conversation
The new parameter makes it possiblt to fail in a way that is more appropriate for user errors: No Starlark stack trace is prepended to the failure, instead the provided causes and their locations are appended to the error message.
By passing the Starlark representation of a module extension tag to
the new `causes` parameter of `fail`, module extensions can generate
more concise and helpful error messages on user errors.
Before:
```
ERROR: Traceback (most recent call last):
File "/home/user/.cache/bazel/_bazel_user/466e6feac151a1e22847383f4e503361/external/gazelle~override/internal/bzlmod/go_deps.bzl", line 165, column 21, in _go_deps_impl
fail("Multiple overrides defined for Go module path \"{}\" in module \"{}\".".format(override_tag.path, module.name))
Error in fail: Multiple overrides defined for Go module path "github.com/stretchr/testify" in module "gazelle_bcr_tests".
```
After:
```
ERROR: Multiple overrides defined for Go module path "github.com/stretchr/testify" in module "gazelle_bcr_tests".
Causes:
bazel_module_tag in file "<root>/MODULE.bazel", line 39, column 25, with value:
go_deps.gazelle_override(
path = "github.com/stretchr/testify",
directives = ["gazelle:go_naming_convention go_default_library"],
)
```
e99efdb to
8346e89
Compare
module_ctx.fail_on_user_errorcauses parameter to fail and use it for extension tags
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.
By passing the Starlark representation of a module extension tag to the new
causesparameter offail, module extensions can generate less verbose and helpful error messages on user errors.Before:
After:
Fixes #17375
Work towards #16763