diff --git a/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java b/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java index 1988d082..e59a7ca2 100644 --- a/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java @@ -64,22 +64,30 @@ public class SaganUpdater { originalVersion, currentVersion, projects); if (updateReleaseException == null) { log.info("Updating Sagan releases with \n\n{}", update); - Project project = this.saganClient.updateRelease(currentVersion.projectName, - Collections.singletonList(update)); - Optional projectVersion = latestVersion(currentVersion, - project); - log.info("Found the following latest project version [{}]", projectVersion); - boolean present = projectVersion.isPresent(); - if (present && currentVersionNewerOrEqual(currentVersion, projectVersion)) { - updateDocumentationIfNecessary(projectFile, project); + try { + Project project = this.saganClient.updateRelease( + currentVersion.projectName, Collections.singletonList(update)); + Optional projectVersion = latestVersion(currentVersion, + project); + log.info("Found the following latest project version [{}]", + projectVersion); + boolean present = projectVersion.isPresent(); + if (present + && currentVersionNewerOrEqual(currentVersion, projectVersion)) { + updateDocumentationIfNecessary(projectFile, project); + } + else { + log.info(present + ? "Latest version [" + projectVersion.get() + "] present and " + + "the current version [" + currentVersion + + "] is older than that one. " + "Will do nothing." + : "No latest version found. Will do nothing."); + return ExecutionResult.skipped(); + } } - else { - log.info(present - ? "Latest version [" + projectVersion.get() + "] present and " - + "the current version [" + currentVersion - + "] is older than that one. " + "Will do nothing." - : "No latest version found. Will do nothing."); - return ExecutionResult.skipped(); + catch (Exception ex) { + log.warn("Exception occurred while trying to update sagan release", ex); + updateReleaseException = ex; } } return updateReleaseException == null ? ExecutionResult.success() diff --git a/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java b/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java index 1368448d..889f0f04 100644 --- a/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java +++ b/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java @@ -19,9 +19,13 @@ package releaser.internal.tech; import java.io.Serializable; import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; + /** * Task execution result. Contains a list of exceptions thrown while running the task. */ @@ -57,11 +61,22 @@ public class ExecutionResult implements Serializable { } public static ExecutionResult failure(Exception throwable) { - return new ExecutionResult(throwable); + return new ExecutionResult(breakReferenceChain(throwable)); } public static ExecutionResult failure(List throwables) { - return new ExecutionResult(throwables); + return new ExecutionResult(throwables.stream() + .map(ExecutionResult::breakReferenceChain).collect(Collectors.toList())); + } + + private static Exception breakReferenceChain(Exception cause) { + if (cause instanceof HttpServerErrorException + || cause instanceof HttpClientErrorException) { + System.out.println("Breaking the reference chain. . . i think"); + return new RuntimeException( + "[Breaking self reference chain] " + cause.toString()); + } + return cause; } public static ExecutionResult unstable(Exception ex) { diff --git a/releaser-spring/src/main/java/releaser/internal/spring/SpringBatchFlowRunner.java b/releaser-spring/src/main/java/releaser/internal/spring/SpringBatchFlowRunner.java index d13450f2..1c56c370 100644 --- a/releaser-spring/src/main/java/releaser/internal/spring/SpringBatchFlowRunner.java +++ b/releaser-spring/src/main/java/releaser/internal/spring/SpringBatchFlowRunner.java @@ -49,6 +49,7 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; +import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.job.builder.FlowBuilder; @@ -423,7 +424,7 @@ class SpringBatchFlowRunner implements FlowRunner, Closeable { List thrownExceptions = exceptionsThrownBySteps(execution); return new ExecutionResult(thrownExceptions); } - catch (JobExecutionException ex) { + catch (JobExecutionException | UnexpectedJobExecutionException ex) { return ExecutionResult.failure(ex); } }