Class Errors
- java.lang.Object
-
- org.elasticsearch.common.inject.internal.Errors
-
public final class Errors extends Object
A collection of error messages. If this type is passed as a method parameter, the method is considered to have executed successfully only if new errors were not added to this collection.Errors can be chained to provide additional context. To add context, call
withSource(java.lang.Object)to create a new Errors instance that contains additional context. All messages added to the returned instance will contain full context.To avoid messages with redundant context,
withSource(java.lang.Object)should be added sparingly. A good rule of thumb is to assume a method's caller has already specified enough context to identify that method. When calling a method that's defined in a different context, call that method with an errors object that includes its context.- Author:
- jessewilson@google.com (Jesse Wilson)
-
-
Method Summary
-
-
-
Constructor Detail
-
Errors
public Errors()
-
Errors
public Errors(Object source)
-
-
Method Detail
-
withSource
public Errors withSource(Object source)
Returns an instance that usessourceas a reference point for newly added errors.
-
missingImplementation
public Errors missingImplementation(Key key)
We use a fairly generic error message here. The motivation is to share the same message for both bind time errors:
...and at provide-time errors:Guice.createInjector(new AbstractModule() { public void configure() { bind(Runnable.class); } }
Otherwise we need to know who's calling when resolving a just-in-time binding, which makes things unnecessarily complex.Guice.createInjector().getInstance(Runnable.class);
-
converterReturnedNull
public Errors converterReturnedNull(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter matchingConverter)
-
conversionTypeError
public Errors conversionTypeError(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter matchingConverter, Object converted)
-
conversionError
public Errors conversionError(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter matchingConverter, RuntimeException cause)
-
ambiguousTypeConversion
public Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral<?> type, MatcherAndConverter a, MatcherAndConverter b)
-
bindingToProvider
public Errors bindingToProvider()
-
subtypeNotProvided
public Errors subtypeNotProvided(Class<? extends Provider<?>> providerType, Class<?> type)
-
recursiveImplementationType
public Errors recursiveImplementationType()
-
recursiveProviderType
public Errors recursiveProviderType()
-
missingScopeAnnotation
public Errors missingScopeAnnotation()
-
optionalConstructor
public Errors optionalConstructor(Constructor constructor)
-
scopeNotFound
public Errors scopeNotFound(Class<? extends Annotation> scopeAnnotation)
-
scopeAnnotationOnAbstractType
public Errors scopeAnnotationOnAbstractType(Class<? extends Annotation> scopeAnnotation, Class<?> type, Object source)
-
misplacedBindingAnnotation
public Errors misplacedBindingAnnotation(Member member, Annotation bindingAnnotation)
-
duplicateScopes
public Errors duplicateScopes(Scope existing, Class<? extends Annotation> annotationType, Scope scope)
-
voidProviderMethod
public Errors voidProviderMethod()
-
missingConstantValues
public Errors missingConstantValues()
-
duplicateBindingAnnotations
public Errors duplicateBindingAnnotations(Member member, Class<? extends Annotation> a, Class<? extends Annotation> b)
-
duplicateScopeAnnotations
public Errors duplicateScopeAnnotations(Class<? extends Annotation> a, Class<? extends Annotation> b)
-
recursiveBinding
public Errors recursiveBinding()
-
errorNotifyingTypeListener
public Errors errorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause)
-
errorInProvider
public Errors errorInProvider(RuntimeException runtimeException)
-
errorInUserInjector
public Errors errorInUserInjector(MembersInjector<?> listener, TypeLiteral<?> type, RuntimeException cause)
-
errorNotifyingInjectionListener
public Errors errorNotifyingInjectionListener(InjectionListener<?> listener, TypeLiteral<?> type, RuntimeException cause)
-
exposedButNotBound
public void exposedButNotBound(Key<?> key)
-
getMessagesFromThrowable
public static Collection<Message> getMessagesFromThrowable(Throwable throwable)
-
errorInUserCode
public Errors errorInUserCode(Throwable cause, String messageFormat, Object... arguments)
-
cannotInjectRawProvider
public Errors cannotInjectRawProvider()
-
cannotInjectRawMembersInjector
public Errors cannotInjectRawMembersInjector()
-
cannotInjectRawTypeLiteral
public Errors cannotInjectRawTypeLiteral()
-
cannotSatisfyCircularDependency
public Errors cannotSatisfyCircularDependency(Class<?> expectedType)
-
throwCreationExceptionIfErrorsExist
public void throwCreationExceptionIfErrorsExist()
-
throwConfigurationExceptionIfErrorsExist
public void throwConfigurationExceptionIfErrorsExist()
-
throwProvisionExceptionIfErrorsExist
public void throwProvisionExceptionIfErrorsExist()
-
merge
public Errors merge(Collection<Message> messages)
-
throwIfNewErrors
public void throwIfNewErrors(int expectedSize) throws ErrorsException- Throws:
ErrorsException
-
toException
public ErrorsException toException()
-
hasErrors
public boolean hasErrors()
-
format
public static String format(String heading, Collection<Message> errorMessages)
Returns the formatted message for an exception with the specified messages.
-
checkForNull
public <T> T checkForNull(T value, Object source, Dependency<?> dependency) throws ErrorsExceptionReturnsvalueif it is non-null allowed to be null. Otherwise a message is added and anErrorsExceptionis thrown.- Throws:
ErrorsException
-
getOnlyCause
public static Throwable getOnlyCause(Collection<Message> messages)
Returns the cause throwable if there is exactly one cause inmessages. If there are zero or multiple messages with causes, null is returned.
-
size
public int size()
-
formatInjectionPoint
public static void formatInjectionPoint(Formatter formatter, Dependency<?> dependency, InjectionPoint injectionPoint)
-
-