Skip to content

Commit

Permalink
Fix error message from getPrerequisites to not print internal details.
Browse files Browse the repository at this point in the history
Part of work on bazelbuild#11993.

Closes bazelbuild#12551.

PiperOrigin-RevId: 344131151
  • Loading branch information
katre authored and copybara-github committed Nov 24, 2020
1 parent e87feb8 commit 8811e27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public List<ConfiguredTarget> getPrerequisites(
throw new QueryException(
caller,
String.format(
"%s %s of type %s does not have attribute '%s'",
errorMsgPrefix, actualConfiguredTarget, rule.getRuleClass(), attrName),
"%sconfigured target of type %s does not have attribute '%s'",
errorMsgPrefix, rule.getRuleClass(), attrName),
ConfigurableQuery.Code.ATTRIBUTE_MISSING);
}
ImmutableList.Builder<ConfiguredTarget> toReturn = ImmutableList.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,13 @@ public void testLabelsFunction_labelListAttribute() throws Exception {
public void testLabelsFunction_errorsOnBadAttribute() throws Exception {
setUpLabelsFunctionTests();

ConfiguredTarget myRule = Iterables.getOnlyElement(eval("//test:my_rule"));
String targetConfiguration = myRule.getConfigurationChecksum();

// Test that the proper error is thrown when requesting an attribute that doesn't exist.
EvalThrowsResult evalThrowsResult = evalThrows("labels('fake_attr', //test:my_rule)", true);
assertConfigurableQueryCode(evalThrowsResult.getFailureDetail(), Code.ATTRIBUTE_MISSING);
assertThat(evalThrowsResult.getMessage())
.isEqualTo(
String.format(
"in 'fake_attr' of rule //test:my_rule: ConfiguredTarget(//test:my_rule, %s) "
+ "of type rule_with_transitions does not have attribute 'fake_attr'",
targetConfiguration));
"in 'fake_attr' of rule //test:my_rule: configured target of type"
+ " rule_with_transitions does not have attribute 'fake_attr'");
}

@Test
Expand Down

0 comments on commit 8811e27

Please sign in to comment.