public static <T> T propagateAuthorizationOrOriginalException(Exception e) { AuthorizationException aex = getFirstThrowableOfType(e, AuthorizationException.class); if (aex != null) throw aex; propagate(e); assert false : "exception should have propagated " + e; return null; }
public static ContextBuilder newBuilder(ProviderMetadata providerMetadata) { try { return new ContextBuilder(providerMetadata); } catch (Exception e) { return propagateAuthorizationOrOriginalException(e); } }
public void testGetFirstThrowableOfTypeFail() { TimeoutException aex = createMock(TimeoutException.class); Message message = new Message(ImmutableList.of(), "test", aex); ProvisionException pex = new ProvisionException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); }
@Test(expectedExceptions = AuthorizationException.class) public void testPropagateCreationExceptionAuthorizationException() throws Throwable { Exception e = new AuthorizationException(); propagateIfPossible( new CreationException(ImmutableSet.of(new Message(ImmutableList.of(), "Error in custom provider", e))), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testPropagateStandardExceptionIllegalArgumentExceptionNestedInHttpResponseException() throws Throwable { Exception e = new IllegalArgumentException(); propagateIfPossible(new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = IllegalStateException.class) public void testPropagateStandardExceptionIllegalStateException() throws Throwable { Exception e = new IllegalStateException(); propagateIfPossible(new RuntimeException(e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
public void testGetFirstThrowableOfTypeSubclass() { SocketException aex = createMock(SocketException.class); assertEquals(getFirstThrowableOfType(aex, IOException.class), aex); }
exceptions = awaitCompletion(responses, exec, maxTime, logger, logPrefix); } catch (TimeoutException te) { throw propagate(te); if (exceptions.size() > 0 && !any(exceptions.values(), containsThrowable(AuthorizationException.class))) { fromIterable = exceptions.keySet(); retryHandler.imposeBackoffExponentialDelay(delayStart, 2, i + 1, maxRetries, return propagateAuthorizationOrOriginalException(new TransformParallelException(Map.class.cast(responses), exceptions, logPrefix));
return; } catch (Throwable throwable) { if (Throwables2.getFirstThrowableOfType(throwable, AuthorizationException.class) != null) { S3ErrorCode code = S3ErrorCode.ACCESS_DENIED; baseRequest.setHandled(true); return; } else if (Throwables2.getFirstThrowableOfType(throwable, TimeoutException.class) != null) { S3ErrorCode code = S3ErrorCode.REQUEST_TIMEOUT;
public void testGetCauseCreation() { AuthorizationException aex = createMock(AuthorizationException.class); Message message = new Message(ImmutableList.of(), "test", aex); CreationException pex = new CreationException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), aex); }
@Test(expectedExceptions = AuthorizationException.class) public void testPropagateProvisionExceptionAuthorizationException() throws Throwable { Exception e = new AuthorizationException(); propagateIfPossible( new ProvisionException(ImmutableSet.of(new Message(ImmutableList.of(), "Error in custom provider", e))), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testPropagateStandardExceptionUnsupportedOperationExceptionNestedInHttpResponseException() throws Throwable { Exception e = new UnsupportedOperationException(); propagateIfPossible(new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testPropagateStandardExceptionUnsupportedOperationException() throws Throwable { Exception e = new UnsupportedOperationException(); propagateIfPossible(new RuntimeException(e), ImmutableSet.<TypeToken<? extends Throwable>> of()); }
@Override protected Object handleInvocation(Object proxy, Method invoked, Object[] argv) throws Throwable { List<Object> args = Arrays.asList(argv); if (all(args, notNull())) args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); Invokable<T, Object> invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); } catch (RuntimeException e) { propagateIfPossible(e, invocation.getInvokable().getExceptionTypes()); throw propagate(e); } }
public void testGetFirstThrowableOfTypeOuter() { AuthorizationException aex = createMock(AuthorizationException.class); assertEquals(getFirstThrowableOfType(aex, AuthorizationException.class), aex); }
exceptions = awaitCompletion(responses, exec, maxTime, logger, logPrefix); } catch (TimeoutException te) { throw propagate(te); if (exceptions.size() > 0 && !any(exceptions.values(), containsThrowable(AuthorizationException.class))) { fromIterable = exceptions.keySet(); retryHandler.imposeBackoffExponentialDelay(delayStart, 2, i + 1, maxRetries, return propagateAuthorizationOrOriginalException(new TransformParallelException(Map.class.cast(responses), exceptions, logPrefix));
@VisibleForTesting static <T extends Throwable> T getFirstThrowableOfType(TransformParallelException e, Class<T> clazz) { for (Exception exception : e.getFromToException().values()) { T cause = getFirstThrowableOfType(exception, clazz); if (cause != null) return cause; } return null; }
public void testGetFirstThrowableOfTypeFailCreation() { TimeoutException aex = createMock(TimeoutException.class); Message message = new Message(ImmutableList.of(), "test", aex); CreationException pex = new CreationException(ImmutableSet.of(message)); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); }
@Test(expectedExceptions = AuthorizationException.class) public void testPropagateProvisionExceptionAuthorizationException() throws Throwable { Exception e = new AuthorizationException(); propagateIfPossible( new ProvisionException(ImmutableSet.of(new Message(ImmutableList.of(), "Error in custom provider", e))), ImmutableSet.<TypeToken<? extends Throwable>> of()); }