Skip to content

Conversation

@fmeum
Copy link
Collaborator

@fmeum fmeum commented Mar 27, 2023

By passing the Starlark representation of a module extension tag to the new causes parameter of fail, module extensions can generate less verbose 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: go_deps: 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 33, column 25, with value:
		go_deps.gazelle_override(
		    path = "github.com/stretchr/testify",
		    directives = ["gazelle:go_naming_convention go_default_library"],
		)
	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 import"],
		)

Fixes #17375
Work towards #16763

fmeum added 3 commits March 28, 2023 10:41
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"],
		)
```
@fmeum fmeum force-pushed the fail-on-user-error branch from e99efdb to 8346e89 Compare March 28, 2023 08:53
@fmeum fmeum changed the title Add module_ctx.fail_on_user_error Add causes parameter to fail and use it for extension tags Mar 28, 2023
@fmeum fmeum closed this Jul 28, 2023
@fmeum fmeum deleted the fail-on-user-error branch July 28, 2023 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow module extensions to fail on a tag

1 participant