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.
  • Loading branch information
katre committed Nov 24, 2020
1 parent ecbf463 commit 529b85a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 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 @@ -161,17 +161,14 @@ 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 529b85a

Please sign in to comment.