Skip to content

Commit

Permalink
Use our own getOrLogException
Browse files Browse the repository at this point in the history
These methods became Internal in 2024.3
  • Loading branch information
RedNesto committed Sep 13, 2024
1 parent 560c78a commit 7093a23
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/main/kotlin/creator/custom/CustomPlatformStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import com.demonwav.mcdev.creator.custom.providers.EmptyLoadedTemplate
import com.demonwav.mcdev.creator.custom.providers.LoadedTemplate
import com.demonwav.mcdev.creator.custom.providers.TemplateProvider
import com.demonwav.mcdev.creator.modalityState
import com.demonwav.mcdev.util.getOrLogException
import com.intellij.ide.wizard.AbstractNewProjectWizardStep
import com.intellij.ide.wizard.GitNewProjectWizardData
import com.intellij.ide.wizard.NewProjectWizardBaseData
import com.intellij.ide.wizard.NewProjectWizardStep
import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.asContextElement
import com.intellij.openapi.diagnostic.getOrLogException
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.openapi.observable.util.transform
Expand All @@ -50,8 +50,6 @@ import com.intellij.ui.dsl.builder.bindText
import com.intellij.util.application
import com.intellij.util.ui.AsyncProcessIcon
import javax.swing.JLabel
import kotlin.collections.component1
import kotlin.collections.component2
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.demonwav.mcdev.creator.custom.PropertyDerivationSelect
import com.demonwav.mcdev.creator.custom.TemplateEvaluator
import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
import com.demonwav.mcdev.creator.custom.types.CreatorProperty
import com.intellij.openapi.diagnostic.getOrLogException
import com.demonwav.mcdev.util.getOrLogException
import com.intellij.openapi.diagnostic.thisLogger

class SelectPropertyDerivation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.demonwav.mcdev.creator.custom.TemplateEvaluator
import com.demonwav.mcdev.creator.custom.TemplatePropertyDescriptor
import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
import com.demonwav.mcdev.util.SemanticVersion
import com.intellij.openapi.diagnostic.getOrLogException
import com.demonwav.mcdev.util.getOrLogException
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.ui.ComboboxSpeedSearch
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/util/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
import java.lang.invoke.MethodHandles
import java.util.Locale
import java.util.concurrent.CancellationException
import kotlin.math.min
import kotlin.reflect.KClass
import org.jetbrains.annotations.NonNls
Expand Down Expand Up @@ -392,6 +393,19 @@ inline fun <T> runCatchingKtIdeaExceptions(action: () -> T): T? = try {
}
}

fun <T> Result<T>.getOrLogException(logger: Logger): T? {
return getOrLogException<T>(logger::error)
}

inline fun <T> Result<T>.getOrLogException(log: (Throwable) -> Unit): T? {
return onFailure { e ->
if (e is ProcessCanceledException || e is CancellationException) {
throw e
}
log(e)
}.getOrNull()
}

fun <T : Throwable> withSuppressed(original: T?, other: T): T =
original?.apply { addSuppressed(other) } ?: other

Expand Down

0 comments on commit 7093a23

Please sign in to comment.