refactor [python]: Drop getOrLogException: it was used only during transition from Kotlin Result.

No need to have 2 similar methods

GitOrigin-RevId: 233e00cd5c9fd94bde4279f63b798d54cd4de7c4
This commit is contained in:
Ilya.Kazakevich
2025-11-13 03:21:47 +00:00
committed by intellij-monorepo-bot
parent 7a677e8dff
commit a3f6519a94
6 changed files with 12 additions and 14 deletions
@@ -33,7 +33,7 @@ import com.intellij.python.community.services.systemPython.SystemPythonService
import com.intellij.python.sdkConfigurator.common.enableSDKAutoConfigurator
import com.intellij.util.PlatformUtils
import com.jetbrains.python.PyBundle
import com.jetbrains.python.getOrLogException
import com.jetbrains.python.orLogException
import com.jetbrains.python.sdk.*
import com.jetbrains.python.sdk.conda.PyCondaSdkCustomizer
import com.jetbrains.python.sdk.configuration.CreateSdkInfoWithTool
@@ -241,7 +241,7 @@ class PythonSdkConfigurator : DirectoryProjectConfigurator {
if (sdkCreator == null) {
return false
}
sdkCreator(true).getOrLogException(thisLogger())
sdkCreator(true).orLogException(thisLogger())
return true
}
@@ -13,7 +13,7 @@ import com.intellij.python.hatch.cli.HatchEnvironment
import com.intellij.python.hatch.getHatchService
import com.intellij.python.hatch.impl.HATCH_TOOL_ID
import com.jetbrains.python.errorProcessing.PyResult
import com.jetbrains.python.getOrLogException
import com.jetbrains.python.orLogException
import com.jetbrains.python.hatch.sdk.createSdk
import com.jetbrains.python.sdk.configuration.*
import com.jetbrains.python.util.runWithModalBlockingOrInBackground
@@ -42,13 +42,13 @@ class PyHatchSdkConfiguration : PyProjectTomlConfigurationExtension {
): EnvCheckerResult = reportRawProgress {
it.text(PyCharmCommunityCustomizationBundle.message("sdk.set.up.hatch.project.analysis"))
val hatchService = module.getHatchService().getOr { return EnvCheckerResult.CannotConfigure }
val canManage = if (checkToml) hatchService.isHatchManagedProject().getOrLogException(LOGGER) == true else true
val canManage = if (checkToml) hatchService.isHatchManagedProject().orLogException(LOGGER) == true else true
val intentionName = PyCharmCommunityCustomizationBundle.message("sdk.set.up.hatch.environment")
val envNotFound = EnvCheckerResult.EnvNotFound(intentionName)
when {
canManage && checkExistence -> {
val defaultEnv = hatchService.findDefaultVirtualEnvironmentOrNull().getOrLogException(LOGGER)?.pythonVirtualEnvironment
val defaultEnv = hatchService.findDefaultVirtualEnvironmentOrNull().orLogException(LOGGER)?.pythonVirtualEnvironment
when (defaultEnv) {
is PythonVirtualEnvironment.Existing -> EnvCheckerResult.EnvFound(defaultEnv.pythonInfo, intentionName)
is PythonVirtualEnvironment.NotExisting, null -> envNotFound
@@ -25,7 +25,7 @@ import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.JBUI
import com.jetbrains.python.PyBundle
import com.jetbrains.python.errorProcessing.PyResult
import com.jetbrains.python.getOrLogException
import com.jetbrains.python.orLogException
import com.jetbrains.python.sdk.PythonSdkType
import com.jetbrains.python.sdk.basePath
import com.jetbrains.python.sdk.configuration.*
@@ -66,7 +66,7 @@ class PyPipfileSdkConfiguration : PyProjectSdkConfigurationExtension {
module: Module, checkExistence: CheckExistence,
): EnvCheckerResult = withBackgroundProgress(module.project, PyBundle.message("python.sdk.validating.environment")) {
val pipfile = findAmongRoots(module, PipEnvFileHelper.PIP_FILE)?.name ?: return@withBackgroundProgress EnvCheckerResult.CannotConfigure
val pipEnvExecutable = getPipEnvExecutable().getOrLogException(LOGGER) ?: return@withBackgroundProgress EnvCheckerResult.CannotConfigure
val pipEnvExecutable = getPipEnvExecutable().orLogException(LOGGER) ?: return@withBackgroundProgress EnvCheckerResult.CannotConfigure
val canManage = pipEnvExecutable.isExecutable()
val intentionName = PyCharmCommunityCustomizationBundle.message("sdk.create.pipenv.suggestion", pipfile)
val envNotFound = EnvCheckerResult.EnvNotFound(intentionName)
@@ -100,7 +100,7 @@ class PyPipfileSdkConfiguration : PyProjectSdkConfigurationExtension {
}
private suspend fun askForEnvData(module: Module, source: Source, envExists: Boolean): PyAddNewPipEnvFromFilePanel.Data? {
val pipEnvExecutable = getPipEnvExecutable().getOrLogException(LOGGER)
val pipEnvExecutable = getPipEnvExecutable().orLogException(LOGGER)
if ((envExists || source == Source.INSPECTION) && pipEnvExecutable?.isExecutable() == true) {
return PyAddNewPipEnvFromFilePanel.Data(pipEnvExecutable)
@@ -16,7 +16,7 @@ import com.intellij.python.pyproject.PyProjectToml
import com.intellij.python.pyproject.model.api.SuggestedSdk
import com.intellij.python.pyproject.model.api.suggestSdk
import com.jetbrains.python.errorProcessing.PyResult
import com.jetbrains.python.getOrLogException
import com.jetbrains.python.orLogException
import com.jetbrains.python.onSuccess
import com.jetbrains.python.sdk.*
import com.jetbrains.python.sdk.configuration.*
@@ -76,7 +76,7 @@ class PyUvSdkConfiguration : PyProjectTomlConfigurationExtension {
}
} ?: return EnvCheckerResult.CannotConfigure
val tomlContentResult = withContext(Dispatchers.Default) { PyProjectToml.parse(tomlFileContent) }
val tomlContent = tomlContentResult.getOrLogException(logger) ?: return EnvCheckerResult.CannotConfigure
val tomlContent = tomlContentResult.orLogException(logger) ?: return EnvCheckerResult.CannotConfigure
val project = tomlContent.project ?: return EnvCheckerResult.CannotConfigure
project.name ?: module.name
}
@@ -179,8 +179,6 @@ inline fun <S, E, E2> Result<S, E>.mapError(code: (E) -> E2): Result<S, E2> =
}
// aliases to drop-in replace for kotlin Result
fun <S, E> Result<S, E>.getOrLogException(logger: Logger): S? = this.orLogException(logger)
fun <S, E> Result<S, E>.getOrLogExceptionAsWarn(logger: Logger): S? = this.orLogExceptionAsWarn(logger)
fun <S, E> Result<S, E>.getOrNull(): S? = this.successOrNull
val <S, E> Result<S, E>.isFailure: Boolean get() = this is Failure
val <S, E> Result<S, E>.isSuccess: Boolean get() = this is Success
@@ -22,7 +22,7 @@ import com.jetbrains.python.PythonInfo
import com.jetbrains.python.Result
import com.jetbrains.python.errorProcessing.MessageError
import com.jetbrains.python.errorProcessing.PyResult
import com.jetbrains.python.getOrLogException
import com.jetbrains.python.orLogException
import com.jetbrains.python.isCondaVirtualEnv
import com.jetbrains.python.pathValidation.PlatformAndRoot.Companion.getPlatformAndRoot
import com.jetbrains.python.pathValidation.ValidationRequest
@@ -342,7 +342,7 @@ internal suspend fun <P : PathHolder> FileSystem<P>.getExistingSelectableInterpr
val languageLevel = sdk.versionString?.let {
PythonSdkFlavor.getLanguageLevelFromVersionStringStaticSafe(it)
} ?: run {
ExecService().validatePythonAndGetInfo(sdk.asBinToExecute()).getOrLogException(LOG)?.languageLevel
ExecService().validatePythonAndGetInfo(sdk.asBinToExecute()).orLogException(LOG)?.languageLevel
}
languageLevel?.let {