/** * Invoke given producer task and gather errors. * <p/> * After the task is complete all gathered errors are logged. No exception is thrown * even if there is a fatal error present in the list of errors. * * @param producer producer task to be invoked. * @return the result produced by the task. */ public static <T> T process(final Producer<T> producer) { return process(producer, false); }
@Override public void run() { Errors.warning(this, LocalizationMessages.RESOURCE_MERGE_CONFLICT_LOCATORS(Resource.Builder.this, resourceBuilder, path)); } });
/** * Add a warning to the list of messages. * * @param source source of the error. * @param message message of the error. */ public static void warning(final Object source, final String message) { error(source, message, Severity.WARNING); }
/** * Removes all issues that have been added since the last marked position as well as * removes the last mark. */ public static void reset() { getInstance()._reset(); }
/** * Remove a previously set mark, if any. */ public static void unmark() { getInstance()._unmark(); }
/** * Set a mark at a current position in the errors messages list. */ public static void mark() { getInstance()._mark(); }
Errors.mark(); // mark begin of validation phase try { if (Errors.fatalIssuesFound() && !ignoreValidationError()) { throw new ModelValidationException(LocalizationMessages.RESOURCE_MODEL_VALIDATION_FAILED_AT_INIT(), ModelErrors.getErrorsAsResourceModelIssues(true)); Errors.logErrors(true); Errors.reset(); // reset errors to the state before validation phase } else { Errors.unmark();
private static <T> T process(final Callable<T> task, final boolean throwException) throws Exception { Errors instance = errors.get(); if (instance == null) { instance = new Errors(); errors.set(instance); } instance.preProcess(); Exception caught = null; try { return task.call(); } catch (Exception re) { // If a runtime exception is caught then report errors and rethrow. caught = re; } finally { instance.postProcess(throwException && caught == null); } throw caught; }
/** * Log errors and return a status flag indicating whether a fatal issue has been found * in the error collection. * <p> * The {@code afterMark} flag indicates whether only those issues should be logged that were * added after a {@link #mark() mark has been set}. * </p> * * @param afterMark if {@code true}, only issues added after a mark has been set are returned, * if {@code false} all issues are returned. * @return {@code true} if there are any fatal issues present in the collection, {@code false} * otherwise. */ public static boolean logErrors(final boolean afterMark) { return logErrors(getInstance()._getErrorMessages(afterMark)); }
/** * Get the list of error messages. * <p> * The {@code afterMark} flag indicates whether only those issues should be returned that were * added after a {@link #mark() mark has been set}. * </p> * * @param afterMark if {@code true}, only issues added after a mark has been set are returned, * if {@code false} all issues are returned. * @return non-null error list. */ public static List<ErrorMessage> getErrorMessages(final boolean afterMark) { return getInstance()._getErrorMessages(afterMark); }
@Override public void onFailure(final ErrorInformation error) throws MultiException { final String msg; switch (error.getErrorType()) { case FAILURE_TO_REIFY: msg = LocalizationMessages.HK_2_REIFICATION_ERROR( error.getDescriptor().getImplementation(), printStackTrace(error.getAssociatedException())); break; default: msg = LocalizationMessages.HK_2_UNKNOWN_ERROR(printStackTrace(error.getAssociatedException())); break; } try { Errors.warning(error.getInjectee(), msg); } catch (IllegalStateException ex) { Errors.process(new Runnable() { @Override public void run() { Errors.warning(this, LocalizationMessages.HK_2_FAILURE_OUTSIDE_ERROR_SCOPE()); Errors.warning(error.getInjectee(), msg); } }); } }
/** * Get the list of all error messages. * * @return non-null error message list. */ public static List<ErrorMessage> getErrorMessages() { return getErrorMessages(false); }
@Override public void visitInvocable(final Invocable invocable) { // TODO: check invocable. Class resClass = invocable.getHandler().getHandlerClass(); if (resClass != null && !checkedClasses.contains(resClass)) { checkedClasses.add(resClass); final boolean provider = Providers.isProvider(resClass); int counter = 0; for (Annotation annotation : resClass.getAnnotations()) { if (SCOPE_ANNOTATIONS.contains(annotation.annotationType())) { counter++; } } if (counter == 0 && provider) { Errors.warning(resClass, LocalizationMessages.RESOURCE_IMPLEMENTS_PROVIDER(resClass, Providers.getProviderContracts(resClass))); } else if (counter > 1) { Errors.fatal(resClass, LocalizationMessages.RESOURCE_MULTIPLE_SCOPE_ANNOTATIONS(resClass)); } } }
/** * Log errors and throw an exception if there are any fatal issues detected and * the {@code throwException} flag has been set to {@code true}. * * @param throwException if set to {@code true}, any fatal issues will cause a {@link ErrorMessagesException} * to be thrown. */ private static void processErrors(final boolean throwException) { final List<ErrorMessage> errors = new ArrayList<ErrorMessage>(Errors.errors.get().issues); boolean isFatal = logErrors(errors); if (throwException && isFatal) { throw new ErrorMessagesException(errors); } }
Errors.mark(); // mark begin of validation phase try { if (Errors.fatalIssuesFound() && !ignoreValidationError()) { throw new ModelValidationException(LocalizationMessages.RESOURCE_MODEL_VALIDATION_FAILED_AT_INIT(), ModelErrors.getErrorsAsResourceModelIssues(true)); Errors.logErrors(true); Errors.reset(); // reset errors to the state before validation phase } else { Errors.unmark();
private static <T> T process(final Callable<T> task, final boolean throwException) throws Exception { Errors instance = errors.get(); if (instance == null) { instance = new Errors(); errors.set(instance); } instance.preProcess(); Exception caught = null; try { return task.call(); } catch (Exception re) { // If a runtime exception is caught then report errors and rethrow. caught = re; } finally { instance.postProcess(throwException && caught == null); } throw caught; }
/** * Log errors and return a status flag indicating whether a fatal issue has been found * in the error collection. * <p> * The {@code afterMark} flag indicates whether only those issues should be logged that were * added after a {@link #mark() mark has been set}. * </p> * * @param afterMark if {@code true}, only issues added after a mark has been set are returned, * if {@code false} all issues are returned. * @return {@code true} if there are any fatal issues present in the collection, {@code false} * otherwise. */ public static boolean logErrors(final boolean afterMark) { return logErrors(getInstance()._getErrorMessages(afterMark)); }
/** * Removes all issues that have been added since the last marked position as well as * removes the last mark. */ public static void reset() { getInstance()._reset(); }
/** * Remove a previously set mark, if any. */ public static void unmark() { getInstance()._unmark(); }
/** * Set a mark at a current position in the errors messages list. */ public static void mark() { getInstance()._mark(); }