diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/Environment.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Environment.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java index 9b17cead89..38cbb7c35f 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java @@ -940,16 +940,28 @@ public final class Environment implements Freezable { } } + /** An exception thrown by {@link #FAIL_FAST_HANDLER}. */ + // TODO(bazel-team): Possibly extend RuntimeException instead of IllegalArgumentException. + public static class FailFastException extends IllegalArgumentException { + public FailFastException(String s) { + super(s); + } + } /** - * The fail fast handler, which throws an {@link IllegalArgumentException} whenever an error or - * warning occurs. + * A handler that immediately throws {@link FailFastException} whenever an error or warning + * occurs. + * + * We do not reuse an existing unchecked exception type, because callers (e.g., test assertions) + * need to be able to distinguish between organically occurring exceptions and exceptions thrown + * by this handler. */ public static final EventHandler FAIL_FAST_HANDLER = new EventHandler() { - @Override - public void handle(Event event) { - Preconditions.checkArgument( - !EventKind.ERRORS_AND_WARNINGS.contains(event.getKind()), event); + @Override + public void handle(Event event) { + if (EventKind.ERRORS_AND_WARNINGS.contains(event.getKind())) { + throw new FailFastException(event.toString()); } - }; + } + }; } |