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.

  • Constructor Details

    • Errors

      public Errors()
    • Errors

      public Errors(Object source)
  • Method Details

    • withSource

      public Errors withSource(Object source)
      Returns an instance that uses source as 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:
      Guice.createInjector(new AbstractModule() {
         public void configure() {
      ...and at provide-time errors:
      Otherwise we need to know who's calling when resolving a just-in-time binding, which makes things unnecessarily complex.
    • 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)
    • notASubtype

      public Errors notASubtype(Class<?> implementationType, Class<?> type)
    • recursiveImplementationType

      public Errors recursiveImplementationType()
    • recursiveProviderType

      public Errors recursiveProviderType()
    • missingRuntimeRetention

      public Errors missingRuntimeRetention(Object source)
    • missingScopeAnnotation

      public Errors missingScopeAnnotation()
    • optionalConstructor

      public Errors optionalConstructor(Constructor constructor)
    • cannotBindToGuiceType

      public Errors cannotBindToGuiceType(String simpleName)
    • 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)
    • missingConstructor

      public Errors missingConstructor(Class<?> implementation)
    • tooManyConstructors

      public Errors tooManyConstructors(Class<?> implementation)
    • duplicateScopes

      public Errors duplicateScopes(Scope existing, Class<? extends Annotation> annotationType, Scope scope)
    • voidProviderMethod

      public Errors voidProviderMethod()
    • missingConstantValues

      public Errors missingConstantValues()
    • cannotInjectInnerClass

      public Errors cannotInjectInnerClass(Class<?> type)
    • 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()
    • bindingAlreadySet

      public Errors bindingAlreadySet(Key<?> key, Object source)
    • childBindingAlreadySet

      public Errors childBindingAlreadySet(Key<?> key)
    • errorInjectingMethod

      public Errors errorInjectingMethod(Throwable cause)
    • errorNotifyingTypeListener

      public Errors errorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause)
    • errorInjectingConstructor

      public Errors errorInjectingConstructor(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()
    • cannotInjectTypeLiteralOf

      public Errors cannotInjectTypeLiteralOf(Type unsupportedType)
    • 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)
    • merge

      public Errors merge(Errors moreErrors)
    • getSources

      public List<Object> getSources()
    • throwIfNewErrors

      public void throwIfNewErrors(int expectedSize) throws ErrorsException
    • toException

      public ErrorsException toException()
    • hasErrors

      public boolean hasErrors()
    • addMessage

      public Errors addMessage(String messageFormat, Object... arguments)
    • addMessage

      public Errors addMessage(Message message)
    • format

      public static String format(String messageFormat, Object... arguments)
    • getMessages

      public List<Message> getMessages()
    • 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 ErrorsException
      Returns value if it is non-null allowed to be null. Otherwise a message is added and an ErrorsException is thrown.
    • getOnlyCause

      public static Throwable getOnlyCause(Collection<Message> messages)
      Returns the cause throwable if there is exactly one cause in messages. If there are zero or multiple messages with causes, null is returned.
    • size

      public int size()
    • convert

      public static Object convert(Object o)
    • formatSource

      public static void formatSource(Formatter formatter, Object source)
    • formatInjectionPoint

      public static void formatInjectionPoint(Formatter formatter, Dependency<?> dependency, InjectionPoint injectionPoint)