From c1563c262e172bcf593b98eba35f1bb792f70766 Mon Sep 17 00:00:00 2001 From: Nathan Harmata Date: Fri, 29 Jan 2016 23:03:03 +0000 Subject: Improve the error message on a missing implicit dep. The old error message didn't include the reason why the target was missing, and it also spammed Blaze users with a "tip" that's only relevant to Blaze developers debugging newly written integration tests. -- MOS_MIGRATED_REVID=113401767 --- .../devtools/build/lib/packages/TargetUtils.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/packages') diff --git a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java index b30c898e1c..470a11e2df 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java +++ b/src/main/java/com/google/devtools/build/lib/packages/TargetUtils.java @@ -235,18 +235,23 @@ public final class TargetUtils { // instanceof returns false if target is null (which is exploited here) if (target instanceof Rule) { Rule rule = (Rule) target; - return !isExplicitDependency(rule, label) - ? ("every rule of type " + rule.getRuleClass() + " implicitly depends upon the target '" - + label + "', but this target could not be found. " - + "If this is an integration test, maybe you forgot to add a mock for your new tool?") - : e.getMessage() + " and referenced by '" + target.getLabel() + "'"; + if (isExplicitDependency(rule, label)) { + return String.format("%s and referenced by '%s'", e.getMessage(), target.getLabel()); + } else { + // N.B. If you see this error message in one of our integration tests during development of + // a change that adds a new implicit dependency when running Blaze, maybe you forgot to add + // a new mock target to the integration test's setup. + return String.format("every rule of type %s implicitly depends upon the target '%s', but " + + "this target could not be found because of: %s", rule.getRuleClass(), label, + e.getMessage()); + } } else if (target instanceof InputFile) { return e.getMessage() + " (this is usually caused by a missing package group in the" + " package-level visibility declaration)"; } else { if (target != null) { - return "in target '" + target.getLabel() + "', no such label '" + label + "': " - + e.getMessage(); + return String.format("in target '%s', no such label '%s': %s", target.getLabel(), label, + e.getMessage()); } return e.getMessage(); } -- cgit v1.2.3