Skip to content

Commit 3d4bb77

Browse files
authored
Include lastException as cause when docker-compose up fails (#732)
Include lastException as cause when docker-compose up fails
1 parent 1c6a65c commit 3d4bb77

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: improvement
2+
improvement:
3+
description: Include lastException as cause when docker-compose up fails
4+
links:
5+
- https://github.com/palantir/docker-compose-rule/pull/732

docker-compose-rule-core/src/main/java/com/palantir/docker/compose/execution/ConflictingContainerRemovingDockerCompose.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ public ConflictingContainerRemovingDockerCompose(DockerCompose dockerCompose, Do
4646

4747
@Override
4848
public void up() throws IOException, InterruptedException {
49+
DockerExecutionException lastException = null;
4950
for (int currRetryAttempt = 0; currRetryAttempt <= retryAttempts; currRetryAttempt++) {
5051
try {
5152
getDockerCompose().up();
5253
return;
5354
} catch (DockerExecutionException e) {
55+
lastException = e;
5456
Set<String> conflictingContainerNames = getConflictingContainerNames(e.getMessage());
5557
if (conflictingContainerNames.isEmpty()) {
5658
// failed due to reason other than conflicting containers, so re-throw
@@ -66,7 +68,7 @@ public void up() throws IOException, InterruptedException {
6668
}
6769
}
6870

69-
throw new DockerExecutionException("docker-compose up failed");
71+
throw new DockerExecutionException("docker-compose up failed", lastException);
7072
}
7173

7274
private void removeContainers(Collection<String> containerNames) throws IOException, InterruptedException {

docker-compose-rule-core/src/main/java/com/palantir/docker/compose/execution/DockerExecutionException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ public DockerExecutionException() {}
2121
public DockerExecutionException(String message) {
2222
super(message);
2323
}
24+
25+
public DockerExecutionException(String message, Throwable cause) {
26+
super(message, cause);
27+
}
2428
}

0 commit comments

Comments
 (0)