Skip to content

Commit f0ad7a9

Browse files
authored
Harden handleError() against secondary exceptions (#7387)
1 parent 3227926 commit f0ad7a9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

rewrite-core/src/main/java/org/openrewrite/scheduling/RecipeRunCycle.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.openrewrite.config.DeclarativeRecipe;
2626
import org.openrewrite.internal.ExceptionUtils;
2727
import org.openrewrite.internal.FindRecipeRunException;
28+
import org.openrewrite.marker.Markup;
2829
import org.openrewrite.internal.RecipeRunException;
2930
import org.openrewrite.internal.StringUtils;
3031
import org.openrewrite.marker.*;
@@ -718,8 +719,13 @@ private void recordSourceFileResult(@Nullable String beforePath, @Nullable Strin
718719
ctx.getOnError().accept(t);
719720

720721
if (t instanceof RecipeRunException && after != null) {
721-
RecipeRunException vt = (RecipeRunException) t;
722-
after = (SourceFile) new FindRecipeRunException(vt).visitNonNull(after, 0);
722+
try {
723+
RecipeRunException vt = (RecipeRunException) t;
724+
after = (SourceFile) new FindRecipeRunException(vt).visitNonNull(after, 0);
725+
} catch (Throwable ignored) {
726+
// Tree is too broken for node-level marker — fall back to marking the whole file
727+
after = Markup.error(after, t);
728+
}
723729
}
724730

725731
// Use the original source file to record the error, not the one that may have been modified by the visitor.

0 commit comments

Comments
 (0)