From c36ce0749393f6ddaca5693531d89c1c7520336d Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 6 Jun 2019 10:24:59 +0200 Subject: [PATCH] Should stop failing on unstable exceptions --- .../release/internal/ReleaserApplication.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java index b005cbbe..76920d86 100644 --- a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java +++ b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java @@ -28,6 +28,7 @@ import org.springframework.cloud.release.internal.options.Options; import org.springframework.cloud.release.internal.options.Parser; import org.springframework.cloud.release.internal.spring.SpringReleaser; import org.springframework.cloud.release.internal.tech.MakeBuildUnstableException; +import org.springframework.core.NestedExceptionUtils; @SpringBootApplication public class ReleaserApplication implements CommandLineRunner { @@ -53,19 +54,29 @@ public class ReleaserApplication implements CommandLineRunner { this.releaser.release(options); } catch (MakeBuildUnstableException ex) { - log.error( - "[BUILD UNSTABLE] The following exceptions took place in the post release process", - ex); - log.error( - "[BUILD UNSTABLE] The release happened successfully, but there were post release issues"); - log.error("[BUILD UNSTABLE] An exception that should make " - + "the build unstable occurred. Will not throw an exception."); + handleUnstableException(ex); } catch (Throwable th) { log.error("Exception occurred for the releaser", th); - throw th; + Throwable mostSpecificCause = NestedExceptionUtils.getMostSpecificCause(th); + if (mostSpecificCause instanceof MakeBuildUnstableException) { + handleUnstableException((MakeBuildUnstableException) mostSpecificCause); + } + else { + throw th; + } } System.exit(0); } + private void handleUnstableException(MakeBuildUnstableException ex) { + log.error( + "[BUILD UNSTABLE] The following exceptions took place in the post release process", + ex); + log.error( + "[BUILD UNSTABLE] The release happened successfully, but there were post release issues"); + log.error("[BUILD UNSTABLE] An exception that should make " + + "the build unstable occurred. Will not throw an exception."); + } + }