diff --git a/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java b/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java index 0ebedaefb8..e005f16c3c 100755 --- a/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java +++ b/aws/core/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java @@ -76,7 +76,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler { error = utils.parseAWSErrorFromContent(request, response); if (error != null) { message = error.getMessage(); - exception = new AWSResponseException(command, response, error); + } } else { try { diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/TestCanRecreateTagLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/TestCanRecreateTagLiveTest.java index b706ccb0f3..4aa74cc027 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/TestCanRecreateTagLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/TestCanRecreateTagLiveTest.java @@ -29,6 +29,7 @@ import org.jclouds.Constants; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.RunNodesException; +import org.jclouds.compute.domain.Template; import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.ssh.jsch.config.JschSshClientModule; @@ -90,9 +91,10 @@ public class TestCanRecreateTagLiveTest { context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); try { - context.getComputeService().runNodesWithTag(tag, 1); + Template template = context.getComputeService().templateBuilder().locationId("us-west-1").build(); + context.getComputeService().runNodesWithTag(tag, 1, template); context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); - context.getComputeService().runNodesWithTag(tag, 1); + context.getComputeService().runNodesWithTag(tag, 1, template); } catch (RunNodesException e) { System.err.println(e.getNodeErrors().keySet()); Throwables.propagate(e); diff --git a/core/src/main/java/org/jclouds/util/Utils.java b/core/src/main/java/org/jclouds/util/Utils.java index 8c0a6d9c50..d638266cb8 100644 --- a/core/src/main/java/org/jclouds/util/Utils.java +++ b/core/src/main/java/org/jclouds/util/Utils.java @@ -544,11 +544,14 @@ public class Utils { return (Exception) throwable; } } - Throwables.propagateIfInstanceOf(exception, IllegalStateException.class); - Throwables.propagateIfInstanceOf(exception, IllegalArgumentException.class); - Throwables.propagateIfInstanceOf(exception, AuthorizationException.class); - Throwables.propagateIfInstanceOf(exception, ResourceNotFoundException.class); - Throwables.propagateIfInstanceOf(exception, HttpResponseException.class); + for (Class propagatableExceptionType : new Class[] { IllegalStateException.class, + UnsupportedOperationException.class, IllegalArgumentException.class, AuthorizationException.class, + ResourceNotFoundException.class, HttpResponseException.class }) { + Throwable throwable = getFirstThrowableOfType(exception, propagatableExceptionType); + if (throwable != null) { + throw (Exception) throwable; + } + } Throwables.throwCause(exception, true); return exception; } diff --git a/core/src/test/java/org/jclouds/util/UtilsTest.java b/core/src/test/java/org/jclouds/util/UtilsTest.java index 550cf545fd..8cb21bba54 100644 --- a/core/src/test/java/org/jclouds/util/UtilsTest.java +++ b/core/src/test/java/org/jclouds/util/UtilsTest.java @@ -164,41 +164,73 @@ public class UtilsTest { @Test(expectedExceptions = IllegalStateException.class) public void testPropagateStandardExceptionIllegalStateException() throws Exception { Exception e = new IllegalStateException(); - assertEquals( - Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)), - e); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); } @Test(expectedExceptions = IllegalArgumentException.class) public void testPropagateStandardExceptionIllegalArgumentException() throws Exception { Exception e = new IllegalArgumentException(); - assertEquals( - Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)), - e); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testPropagateStandardExceptionUnsupportedOperationException() throws Exception { + Exception e = new UnsupportedOperationException(); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); } @Test(expectedExceptions = AuthorizationException.class) public void testPropagateStandardExceptionAuthorizationException() throws Exception { Exception e = new AuthorizationException(); - assertEquals( - Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)), - e); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); } @Test(expectedExceptions = ResourceNotFoundException.class) public void testPropagateStandardExceptionResourceNotFoundException() throws Exception { Exception e = new ResourceNotFoundException(); - assertEquals( - Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)), - e); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + } + + @Test(expectedExceptions = IllegalStateException.class) + public void testPropagateStandardExceptionIllegalStateExceptionNestedInHttpResponseException() throws Exception { + Exception e = new IllegalStateException(); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException( + "goo", createNiceMock(HttpCommand.class), null, e)); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testPropagateStandardExceptionIllegalArgumentExceptionNestedInHttpResponseException() throws Exception { + Exception e = new IllegalArgumentException(); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException( + "goo", createNiceMock(HttpCommand.class), null, e)); + } + + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testPropagateStandardExceptionUnsupportedOperationExceptionNestedInHttpResponseException() + throws Exception { + Exception e = new UnsupportedOperationException(); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException( + "goo", createNiceMock(HttpCommand.class), null, e)); + } + + @Test(expectedExceptions = AuthorizationException.class) + public void testPropagateStandardExceptionAuthorizationExceptionNestedInHttpResponseException() throws Exception { + Exception e = new AuthorizationException(); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException( + "goo", createNiceMock(HttpCommand.class), null, e)); + } + + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testPropagateStandardExceptionResourceNotFoundExceptionNestedInHttpResponseException() throws Exception { + Exception e = new ResourceNotFoundException(); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException( + "goo", createNiceMock(HttpCommand.class), null, e)); } @Test(expectedExceptions = HttpResponseException.class) public void testPropagateStandardExceptionHttpResponseException() throws Exception { Exception e = new HttpResponseException("goo", createNiceMock(HttpCommand.class), null); - assertEquals( - Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)), - e); + Utils.returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); } }