List of usage examples for com.google.common.base Throwables getCausalChain
@Beta @CheckReturnValue public static List<Throwable> getCausalChain(Throwable throwable)
From source file:org.isisaddons.module.security.integtests.ThrowableMatchers.java
public static <T extends Throwable> Matcher<T> causalChainContains(final Class<?> cls) { return new TypeSafeMatcher<T>() { @Override//from w ww .j a v a2 s . c o m protected boolean matchesSafely(T item) { final List<Throwable> causalChain = Throwables.getCausalChain(item); for (Throwable t : causalChain) { if (cls.isAssignableFrom(t.getClass())) { return true; } } return false; } @Override public void describeTo(Description description) { description.appendText("causal chain contains " + cls.getName()); } }; }
From source file:com.android.build.gradle.integration.common.utils.GradleExceptionsHelper.java
/** * Gets the message printed at the bottom of the console output, after a task has failed. *///from w w w . j a v a 2 s .c o m public static String getTaskFailureMessage(GradleConnectionException e) { for (Throwable throwable : Throwables.getCausalChain(e)) { // Because of different class loaders involved, we are forced to do stringly-typed // programming. if (throwable.getClass().getName().equals(PlaceholderException.class.getName())) { if (throwable.toString().startsWith(TaskExecutionException.class.getName())) { return throwable.getCause().getMessage(); } } } throw new AssertionError(String.format("Exception was not caused by a task failure: \n%s", Throwables.getStackTraceAsString(e))); }
From source file:org.apache.isis.core.integtestsupport.ThrowableMatchers.java
public static TypeSafeMatcher<Throwable> causedBy(final Class<?> type) { return new TypeSafeMatcher<Throwable>() { @Override//from w w w.j a v a2 s . c om protected boolean matchesSafely(final Throwable throwable) { final List<Throwable> causalChain = Throwables.getCausalChain(throwable); return !FluentIterable.from(causalChain).filter(type).isEmpty(); } @Override public void describeTo(final Description description) { description.appendText("Caused by " + type.getName()); } }; }
From source file:com.android.build.gradle.integration.common.utils.GradleExceptionsHelper.java
public static String getFailureMessage(GradleConnectionException e, Class<?> exceptionType) { for (Throwable throwable : Throwables.getCausalChain(e)) { // Because of different class loaders involved, we are forced to do stringly-typed // programming. if (throwable.getClass().getName().equals(exceptionType.getName())) { return throwable.getMessage(); }/*from w ww .j a v a 2s.co m*/ } throw new AssertionError(String.format("Exception was not caused by a '%s' failure: \n%s", exceptionType.getName(), Throwables.getStackTraceAsString(e))); }
From source file:com.brighttag.agathon.resources.ServiceUnavailableExceptionMapper.java
private static String getMessage(Throwable exception) { String name = NAME_JOINER//w w w .j a v a2s .com .join(FluentIterable.from(Throwables.getCausalChain(exception)).transform(EXCEPTION_NAME).toList()); Throwable rootCause = Throwables.getRootCause(exception); return String.format("%s: %s", name, rootCause.getMessage()); }
From source file:org.jclouds.abiquo.functions.ReturnFalseOn5xx.java
@Override public Object apply(final Exception from) { Throwable exception = Iterables.find(Throwables.getCausalChain(from), hasResponse(from), null); if (exception != null) { HttpResponseException responseException = (HttpResponseException) exception; HttpResponse response = responseException.getResponse(); if (response != null && response.getStatusCode() >= 500 && response.getStatusCode() < 600) { return false; }/*from w w w. j a va 2 s .c o m*/ } throw Throwables.propagate(from); }
From source file:org.jclouds.abiquo.functions.ReturnMovedResource.java
@Override public T apply(final Exception from) { Throwable exception = Iterables.find(Throwables.getCausalChain(from), isMovedException(from), null); if (exception != null) { HttpResponseException responseException = (HttpResponseException) exception; HttpResponse response = responseException.getResponse(); return getMovedEntity(response); }/*from w w w. j a v a 2s . c om*/ throw Throwables.propagate(from); }
From source file:com.greensopinion.swagger.jaxrsgen.mock.noswagger.model.ServerError.java
private String computeMessage(Throwable t) { Optional<Throwable> found = Iterables.tryFind(Throwables.getCausalChain(t), new Predicate<Throwable>() { @Override/*from w w w . j a v a 2 s . c o m*/ public boolean apply(Throwable input) { return input != null && !Strings.isNullOrEmpty(input.getMessage()); } }); if (found.isPresent()) { return found.get().getMessage(); } return null; }
From source file:org.jclouds.abiquo.functions.ReturnAbiquoExceptionOnNotFoundOr4xx.java
@Override public Object apply(final Exception from) { Throwable exception = Iterables.find(Throwables.getCausalChain(from), isNotFoundAndHasAbiquoException(from), null);/* ww w .j ava 2s.co m*/ throw Throwables.propagate(exception == null ? from : (AbiquoException) exception.getCause()); }
From source file:org.jclouds.abiquo.functions.ReturnNullOn303.java
@Override public Object apply(final Exception from) { Throwable exception = Iterables.find(Throwables.getCausalChain(from), hasResponse(from), null); if (exception != null) { HttpResponseException responseException = (HttpResponseException) exception; HttpResponse response = responseException.getResponse(); if (response != null && response.getStatusCode() == Status.SEE_OTHER.getStatusCode()) { return null; }// w w w .j av a2 s. com } throw Throwables.propagate(from); }