Skip to content

Commit 2db9fc6

Browse files
fmeumcopybara-github
authored andcommitted
Add tag name to error messages
Before this change, the error only included the location of the tag. Closes #26001. PiperOrigin-RevId: 758564950 Change-Id: I3f51492585b7149401379c373de7225649219cfa
1 parent 4ee5a3e commit 2db9fc6

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/AttributeValues.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ public static void validateSingleAttr(
6262
String repoName = label.getRepository().getName();
6363
throw Starlark.errorf(
6464
"no repository visible as '@%s' %s, but referenced by label '@%s//%s:%s' in"
65-
+ " attribute '%s' of %s.",
66-
repoName, where, repoName, label.getPackageName(), label.getName(), attrName, what);
65+
+ " attribute '%s'%s.",
66+
repoName,
67+
where,
68+
repoName,
69+
label.getPackageName(),
70+
label.getName(),
71+
attrName,
72+
what.isEmpty() ? "" : " of " + what);
6773
}
6874

6975
private static Optional<Label> getFirstNonVisibleLabel(Object nativeAttrValue) {

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/TypeCheckedTag.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public static TypeCheckedTag create(
6666
if (attrIndex == null) {
6767
throw ExternalDepsException.withMessage(
6868
Code.BAD_MODULE,
69-
"in tag at %s, unknown attribute %s provided%s",
69+
"in '%s' tag at %s, unknown attribute %s provided%s",
70+
tag.getTagName(),
7071
tag.getLocation(),
7172
attrValue.getKey(),
7273
SpellChecker.didYouMean(attrValue.getKey(), tagClass.attributeIndices().keySet()));
@@ -80,7 +81,8 @@ public static TypeCheckedTag create(
8081
throw ExternalDepsException.withCauseAndMessage(
8182
Code.BAD_MODULE,
8283
e,
83-
"in tag at %s, error converting value for attribute %s",
84+
"in '%s' tag at %s, error converting value for attribute %s",
85+
tag.getTagName(),
8486
tag.getLocation(),
8587
attr.getPublicName());
8688
}
@@ -89,7 +91,8 @@ public static TypeCheckedTag create(
8991
if (attr.checkAllowedValues() && !attr.getAllowedValues().apply(nativeValue)) {
9092
throw ExternalDepsException.withMessage(
9193
Code.BAD_MODULE,
92-
"in tag at %s, the value for attribute %s %s",
94+
"in '%s' tag at %s, the value for attribute %s %s",
95+
tag.getTagName(),
9396
tag.getLocation(),
9497
attr.getPublicName(),
9598
attr.getAllowedValues().getErrorReason(nativeValue));
@@ -105,7 +108,8 @@ public static TypeCheckedTag create(
105108
if (attr.isMandatory() && attrValues[i] == null) {
106109
throw ExternalDepsException.withMessage(
107110
Code.BAD_MODULE,
108-
"in tag at %s, mandatory attribute %s isn't being specified",
111+
"in '%s' tag at %s, mandatory attribute %s isn't being specified",
112+
tag.getTagName(),
109113
tag.getLocation(),
110114
attr.getPublicName());
111115
}
@@ -117,10 +121,14 @@ public static TypeCheckedTag create(
117121
attr.getPublicName(),
118122
attrValues[i],
119123
String.format("to the %s", moduleDisplayString),
120-
String.format("tag '%s'", tag.getTagName()));
124+
/* what= */ "");
121125
} catch (EvalException e) {
122126
throw ExternalDepsException.withMessage(
123-
Code.BAD_MODULE, "in tag at %s: %s", tag.getLocation(), e.getMessage());
127+
Code.BAD_MODULE,
128+
"in '%s' tag at %s: %s",
129+
tag.getTagName(),
130+
tag.getLocation(),
131+
e.getMessage());
124132
}
125133
}
126134
return new TypeCheckedTag(

src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,9 +1269,8 @@ public void nonVisibleLabelInLabelAttrForwardedFromTag() throws Exception {
12691269
.hasMessageThat()
12701270
.isEqualTo(
12711271
"""
1272-
in tag at /workspace/MODULE.bazel:2:10: no repository visible as '@other_repo' to the \
1273-
root module, but referenced by label '@other_repo//:foo' in attribute 'label' of tag \
1274-
'label'.\
1272+
in 'label' tag at /workspace/MODULE.bazel:2:10: no repository visible as '@other_repo' \
1273+
to the root module, but referenced by label '@other_repo//:foo' in attribute 'label'.\
12751274
""");
12761275
}
12771276

0 commit comments

Comments
 (0)