Breaking the exception cycle
This commit is contained in:
@@ -64,13 +64,16 @@ 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));
|
||||
try {
|
||||
Project project = this.saganClient.updateRelease(
|
||||
currentVersion.projectName, Collections.singletonList(update));
|
||||
Optional<ProjectVersion> projectVersion = latestVersion(currentVersion,
|
||||
project);
|
||||
log.info("Found the following latest project version [{}]", projectVersion);
|
||||
log.info("Found the following latest project version [{}]",
|
||||
projectVersion);
|
||||
boolean present = projectVersion.isPresent();
|
||||
if (present && currentVersionNewerOrEqual(currentVersion, projectVersion)) {
|
||||
if (present
|
||||
&& currentVersionNewerOrEqual(currentVersion, projectVersion)) {
|
||||
updateDocumentationIfNecessary(projectFile, project);
|
||||
}
|
||||
else {
|
||||
@@ -82,6 +85,11 @@ public class SaganUpdater {
|
||||
return ExecutionResult.skipped();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
log.warn("Exception occurred while trying to update sagan release", ex);
|
||||
updateReleaseException = ex;
|
||||
}
|
||||
}
|
||||
return updateReleaseException == null ? ExecutionResult.success()
|
||||
: ExecutionResult.unstable(
|
||||
new IllegalStateException(updateReleaseException.getMessage()));
|
||||
|
||||
@@ -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<Exception> 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) {
|
||||
|
||||
@@ -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<Exception> thrownExceptions = exceptionsThrownBySteps(execution);
|
||||
return new ExecutionResult(thrownExceptions);
|
||||
}
|
||||
catch (JobExecutionException ex) {
|
||||
catch (JobExecutionException | UnexpectedJobExecutionException ex) {
|
||||
return ExecutionResult.failure(ex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user