From f2d1f5990b51bc343de48b1a4a781d737ed04abb Mon Sep 17 00:00:00 2001 From: Manoj Date: Mon, 2 Mar 2015 00:23:38 +0530 Subject: [PATCH] #5 Better logging on failure to fetch artifacts --- fetch/src/main/java/com/indix/gocd/s3fetch/FetchExecutor.java | 4 +++- .../test/java/com/indix/gocd/s3fetch/FetchExecutorTest.java | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fetch/src/main/java/com/indix/gocd/s3fetch/FetchExecutor.java b/fetch/src/main/java/com/indix/gocd/s3fetch/FetchExecutor.java index 4057c28..d64c0ac 100644 --- a/fetch/src/main/java/com/indix/gocd/s3fetch/FetchExecutor.java +++ b/fetch/src/main/java/com/indix/gocd/s3fetch/FetchExecutor.java @@ -39,7 +39,9 @@ public ExecutionResult execute(TaskConfig config, final TaskExecutionContext con try { store.getPrefix(artifactPathOnS3, destination); } catch (Exception e) { - return ExecutionResult.failure("Failure while downloading artifacts", e); + String message = String.format("Failure while downloading artifacts - %s", e.getMessage()); + logger.error(message, e); + return ExecutionResult.failure(message, e); } return ExecutionResult.success("Fetched all artifacts"); diff --git a/fetch/src/test/java/com/indix/gocd/s3fetch/FetchExecutorTest.java b/fetch/src/test/java/com/indix/gocd/s3fetch/FetchExecutorTest.java index 1c42926..a565d73 100644 --- a/fetch/src/test/java/com/indix/gocd/s3fetch/FetchExecutorTest.java +++ b/fetch/src/test/java/com/indix/gocd/s3fetch/FetchExecutorTest.java @@ -81,12 +81,12 @@ public void shouldBeFailureIfUnableToFetchArtifacts() { Map mockVariables = mockEnvironmentVariables.build(); AmazonS3Client mockClient = mockClient(); doReturn(mockClient).when(fetchExecutor).s3Client(any(GoEnvironment.class)); - doThrow(new AmazonClientException("Exception")).when(mockClient).listObjects(any(ListObjectsRequest.class)); + doThrow(new AmazonClientException("Exception message")).when(mockClient).listObjects(any(ListObjectsRequest.class)); ExecutionResult executionResult = fetchExecutor.execute(config, mockContext(mockVariables)); assertFalse(executionResult.isSuccessful()); - assertThat(executionResult.getMessagesForDisplay(), is("Failure while downloading artifacts")); + assertThat(executionResult.getMessagesForDisplay(), is("Failure while downloading artifacts - Exception message")); } @Test