From a788a9770dd8ae8ddd9764bf715a19d23df542c3 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:37:40 -0700 Subject: [PATCH] fix(userdev): invalidate caches for preceding steps when a step fails (#250) * userdev: invalidate caches for preceding steps when a step fails a common cause for patch apply failing is decompiling with the wrong jdk, and we don't want to have to manually clean cache to fix it after replacing the jdk * adjust message --- .../internal/setup/step/ApplyDevBundlePatches.kt | 3 +-- .../userdev/internal/setup/step/steps.kt | 13 +++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/ApplyDevBundlePatches.kt b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/ApplyDevBundlePatches.kt index 610a7ce..f9630a8 100644 --- a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/ApplyDevBundlePatches.kt +++ b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/ApplyDevBundlePatches.kt @@ -76,8 +76,7 @@ class ApplyDevBundlePatches( op.operate().throwOnError() } catch (ex: Exception) { throw PaperweightException( - "Failed to apply dev bundle patches. See the log file at '${log.toFile()}' for more details. " + - "Usually, the issue is with the dev bundle itself, and not the userdev project.", + "Failed to apply dev bundle patches. See the log file at '${log.toFile()}' for more details.", ex ) } diff --git a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/steps.kt b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/steps.kt index 9237902..dbae6e4 100644 --- a/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/steps.kt +++ b/paperweight-userdev/src/main/kotlin/io/papermc/paperweight/userdev/internal/setup/step/steps.kt @@ -22,6 +22,7 @@ package io.papermc.paperweight.userdev.internal.setup.step +import io.papermc.paperweight.PaperweightException import io.papermc.paperweight.userdev.internal.setup.SetupHandler import io.papermc.paperweight.userdev.internal.setup.UserdevSetup import io.papermc.paperweight.userdev.internal.setup.util.HashFunction @@ -29,6 +30,7 @@ import io.papermc.paperweight.userdev.internal.setup.util.HashFunctionBuilder import io.papermc.paperweight.userdev.internal.setup.util.buildHashFunction import java.nio.file.Path import java.util.concurrent.ConcurrentHashMap +import kotlin.io.path.* import kotlin.reflect.KClass import kotlin.reflect.KProperty1 import kotlin.reflect.full.declaredMemberProperties @@ -73,8 +75,15 @@ object StepExecutor { } } - for (step in steps) { - executeStep(context, step) + try { + for (step in steps) { + executeStep(context, step) + } + } catch (ex: Exception) { + for (step in steps) { + step.hashFile.deleteIfExists() + } + throw PaperweightException("Failed to execute steps, invalidated relevant caches. Run with --stacktrace for more details.", ex) } }