Skip to content

Commit

Permalink
Add detailed rule class/label info when report attribute checking error
Browse files Browse the repository at this point in the history
This PR addresses comment by @gregestren  in #2531

Closes #2546.

--
Reviewed-on: #2546
PiperOrigin-RevId: 148201730
MOS_MIGRATED_REVID=148201730
  • Loading branch information
llhe authored and iirina committed Feb 22, 2017
1 parent ee5797a commit d5912eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public <T> T get(String attributeName, Type<T> type) {
} catch (ClassCastException e) {
// getIndexWithTypeCheck checks the type is right, but unexpected configurable attributes
// can still trigger cast exceptions.
throw new IllegalArgumentException(
"wrong type for attribute \"" + attributeName + "\" in rule " + ruleLabel, e);
throw new IllegalArgumentException("wrong type for attribute \"" + attributeName + "\" in "
+ ruleClass + " rule " + ruleLabel, e);
}
}

Expand Down Expand Up @@ -212,8 +212,8 @@ protected static <T> SelectorList<T> getSelectorList(
return null;
}
if (((SelectorList<?>) attrValue).getOriginalType() != type) {
throw new IllegalArgumentException("Attribute " + attributeName
+ " is not of type " + type + " in rule " + ruleLabel);
throw new IllegalArgumentException("Attribute " + attributeName + " is not of type " + type
+ " in " + ruleClass + " rule " + ruleLabel);
}
return (SelectorList<T>) attrValue;
}
Expand All @@ -225,13 +225,14 @@ protected static <T> SelectorList<T> getSelectorList(
private int getIndexWithTypeCheck(String attrName, Type<?> type) {
Integer index = ruleClass.getAttributeIndex(attrName);
if (index == null) {
throw new IllegalArgumentException("No such attribute " + attrName
+ " in rule " + ruleLabel.getName());
throw new IllegalArgumentException(
"No such attribute " + attrName + " in " + ruleClass + " rule " + ruleLabel);
}
Attribute attr = ruleClass.getAttribute(index);
if (attr.getType() != type) {
throw new IllegalArgumentException("Attribute " + attrName
+ " is of type " + attr.getType() + " and not of type " + type + " in rule " + ruleLabel);
throw new IllegalArgumentException(
"Attribute " + attrName + " is of type " + attr.getType() + " and not of type " + type
+ " in " + ruleClass + " rule " + ruleLabel);
}
return index;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public void testCreateRule() throws Exception {
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Attribute my-labellist-attr is of type list(label) "
+ "and not of type string in rule //testpackage:my-rule-A");
+ "and not of type string in ruleA rule //testpackage:my-rule-A");
}
}

Expand Down

0 comments on commit d5912eb

Please sign in to comment.