bazelbuild / bazelbuild/bazel

Reformat standard visibility error message

Open
#25,941 1 comment 1 reaction 1 assignee Claimed by @brandjon View on GitHub
P2 team-Loading-API type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

After #25933 is implemented, which provides a verbose mode for visibility errors, we can maybe condense the standard error message used when verbosity is not enabled. Right now, this error looks like

```
ERROR: experimental/users/brandjon/symmac/BUILD:7:10: in cc_library rule //experimental/users/brandjon/symmac:B_actual: Visibility error:
alias '//experimental/users/brandjon/symmac:A' referring to target '//experimental/users/brandjon/symmac:A_actual' is not visible from
target '//experimental/users/brandjon/symmac:B_actual'
Recommendation: modify the visibility declaration if you think the dependency is legitimate. For more info see https://bazel.build/concepts/visibility
```

Problems:
* The location at the start of the message is arbitrary and confusing in the case that the rule was declared in a symbolic macro. This is tracked separately in #25940.
* The consuming target is displayed twice, first immediately after the location (before "Visibility error:"), and then again in the "not visible from" message.
* The recommendation may not be applicable. This is tracked separately in #25933.
* The alias information is actually totally irrelevant. Aliases do not forward visibility permissions of the target they refer to; it is the alias's own visibility that matters, just like any other kind of rule.
* The error message puts the dependency and consumer target descriptions at the start of two separate lines. This makes grepping for "x is not visible from y" harder (needed for tests and scripts). The original motivation for this was readability, but that's moot once #25933 lands.

The solution is to replace the message with something like

> ERROR: experimental/users/brandjon/symmac/BUILD:7:10: in cc_library rule //experimental/users/brandjon/symmac:B_actual: dependency on target '//experimental/users/brandjon/symmac:A' violates its visibility. For more diagnostic information, rerun with the flag --verbose_visibility_errors.

(all on one line -- I avoided triple-quoting in order to show it with line wrapping, as in the terminal)

Grepping can match for `"bar: dependency on target 'foo' violates its visibility."`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.