From 439a73df6185140dab571bb627597e32a98e5f94 Mon Sep 17 00:00:00 2001 From: Laurent Le Brun Date: Mon, 22 Jun 2015 16:11:37 +0000 Subject: Error message when attribute is of the wrong type is misleading Fixes #241 -- MOS_MIGRATED_REVID=96573740 --- .../devtools/build/lib/packages/RuleFactory.java | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java index d5d1a46e8d..a9408ee754 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java @@ -69,15 +69,21 @@ public class RuleFactory { *

It is the caller's responsibility to add the rule to the package (the caller may choose not * to do so if, for example, the rule has errors).

*/ - static Rule createRule(Package.Builder pkgBuilder, RuleClass ruleClass, - Map attributeValues, EventHandler eventHandler, FuncallExpression ast, + static Rule createRule( + Package.Builder pkgBuilder, + RuleClass ruleClass, + Map attributeValues, + EventHandler eventHandler, + FuncallExpression ast, Location location) throws InvalidRuleException, NameConflictException { Preconditions.checkNotNull(ruleClass); String ruleClassName = ruleClass.getName(); Object nameObject = attributeValues.get("name"); - if (!(nameObject instanceof String)) { + if (nameObject == null) { throw new InvalidRuleException(ruleClassName + " rule has no 'name' attribute"); + } else if (!(nameObject instanceof String)) { + throw new InvalidRuleException(ruleClassName + " 'name' attribute must be a string"); } String name = (String) nameObject; Label label; @@ -88,14 +94,14 @@ public class RuleFactory { } catch (Label.SyntaxException e) { throw new InvalidRuleException("illegal rule name: " + name + ": " + e.getMessage()); } - boolean inWorkspaceFile = location.getPath() != null - && location.getPath().getBaseName().contains("WORKSPACE"); + boolean inWorkspaceFile = + location.getPath() != null && location.getPath().getBaseName().contains("WORKSPACE"); if (ruleClass.getWorkspaceOnly() && !inWorkspaceFile) { - throw new RuleFactory.InvalidRuleException(ruleClass + " must be in the WORKSPACE file " - + "(used by " + label + ")"); + throw new RuleFactory.InvalidRuleException( + ruleClass + " must be in the WORKSPACE file " + "(used by " + label + ")"); } else if (!ruleClass.getWorkspaceOnly() && inWorkspaceFile) { - throw new RuleFactory.InvalidRuleException(ruleClass + " cannot be in the WORKSPACE file " - + "(used by " + label + ")"); + throw new RuleFactory.InvalidRuleException( + ruleClass + " cannot be in the WORKSPACE file " + "(used by " + label + ")"); } try { -- cgit v1.2.3