summaryrefslogtreecommitdiffstats
path: root/sangria-core/src/main/java/com
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-07 21:09:20 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-07 21:10:05 -0400
commit505b147bd23e26d21932af2c3336c9f4607bbcce (patch)
treea5e58915ccacd82cb8d4f4b9a9808c318e34573e /sangria-core/src/main/java/com
parentdf9dbddd378e6f5adadb3b62279fb80eb92b4a91 (diff)
downloadsangria-505b147bd23e26d21932af2c3336c9f4607bbcce.tar.xz
core: Make DelayedError complain if cancel() is called too late.
Diffstat (limited to 'sangria-core/src/main/java/com')
-rw-r--r--sangria-core/src/main/java/com/tavianator/sangria/core/DelayedError.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/sangria-core/src/main/java/com/tavianator/sangria/core/DelayedError.java b/sangria-core/src/main/java/com/tavianator/sangria/core/DelayedError.java
index d6f86a8..2aeabca 100644
--- a/sangria-core/src/main/java/com/tavianator/sangria/core/DelayedError.java
+++ b/sangria-core/src/main/java/com/tavianator/sangria/core/DelayedError.java
@@ -25,6 +25,8 @@ import com.google.inject.CreationException;
import com.google.inject.Injector;
import com.google.inject.spi.Message;
+import static com.google.common.base.Preconditions.*;
+
/**
* Similar to {@link Binder#addError(String, Object...)}, but can be canceled later. Useful for enforcing correct usage
* of fluent APIs.
@@ -35,6 +37,7 @@ import com.google.inject.spi.Message;
*/
public class DelayedError {
private Throwable error;
+ private boolean reported = false;
/**
* Create a {@link DelayedError}.
@@ -85,11 +88,13 @@ public class DelayedError {
* Cancel this error.
*/
public void cancel() {
- this.error = null;
+ checkState(!reported, "This error has already been reported");
+ error = null;
}
@Inject
- void inject(Injector injector) throws Throwable {
+ void reportErrors(Injector injector) throws Throwable {
+ reported = true;
if (error != null) {
throw error;
}