Skip to content

Commit 7ed9a55

Browse files
committed
Leverage wither to add downloading exceptions.
1 parent 78e9eee commit 7ed9a55

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

rewrite-core/src/main/java/org/openrewrite/RecipeRunException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public RecipeRunException(Throwable cause) {
4141
this(cause, null);
4242
}
4343

44-
public static String getSanitizedStackTrace(Throwable cause) {
44+
public String getSanitizedStackTrace() {
4545
StringJoiner sanitized = new StringJoiner("\n");
46-
sanitized.add(cause.getClass().getName() + ": " + cause.getLocalizedMessage());
46+
sanitized.add(getCause().getClass().getName() + ": " + getCause().getLocalizedMessage());
4747

4848
int i = 0;
49-
for (StackTraceElement stackTraceElement : cause.getStackTrace()) {
49+
for (StackTraceElement stackTraceElement : getCause().getStackTrace()) {
5050
if (stackTraceElement.getClassName().equals(RecipeScheduler.class.getName())) {
5151
break;
5252
}

rewrite-core/src/main/java/org/openrewrite/Tree.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ default <T2 extends Tree> T2 safeCast() {
134134
@SuppressWarnings("unchecked")
135135
default <T extends Tree> T withException(Throwable throwable, @Nullable ExecutionContext ctx) {
136136
if (ctx != null) {
137+
ctx.getOnError().accept(throwable);
137138
ctx.putMessage(Recipe.PANIC, "true");
138139
}
139140
RecipeRunException rre;

rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeDependencyVersion.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openrewrite.internal.lang.Nullable;
2323
import org.openrewrite.maven.internal.MavenDownloadingException;
2424
import org.openrewrite.maven.tree.*;
25+
import org.openrewrite.semver.LatestPatch;
2526
import org.openrewrite.semver.Semver;
2627
import org.openrewrite.semver.VersionComparator;
2728
import org.openrewrite.xml.AddToTagVisitor;
@@ -228,14 +229,22 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
228229
}
229230
}
230231
} catch (MavenDownloadingException exception) {
231-
ctx.getOnError().accept(exception);
232-
return t.withMarkers(t.getMarkers().searchResult(UncaughtVisitorException.getSanitizedStackTrace(exception)));
232+
return t.withException(exception, ctx);
233233
}
234234
return t;
235235
}
236236

237237
@Nullable
238238
private String findNewerVersion(String groupId, String artifactId, String version, ExecutionContext ctx) {
239+
240+
if (versionComparator instanceof LatestPatch) {
241+
//In the case of latest patch, a new version can only be derived if the current version is a semantic
242+
//version. Check if the current version is valid candidate before attempting to download metadata.
243+
if (!versionComparator.isValid(version, version)) {
244+
return null;
245+
}
246+
}
247+
239248
try {
240249
MavenMetadata mavenMetadata = downloadMetadata(groupId, artifactId, ctx);
241250
List<String> versions = new ArrayList<>();

0 commit comments

Comments
 (0)