Skip to content

Commit fca67fb

Browse files
authored
Fix #2022. Handle exception thrown on run lambda debug under dotnet 3.1 runtime (#2023)
1 parent 9041118 commit fca67fb

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

jetbrains-rider/src/software/aws/toolkits/jetbrains/services/lambda/LambdaDaemonHost.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.psi.SmartPointerManager
1919
import com.jetbrains.rdclient.util.idea.LifetimedProjectComponent
2020
import com.jetbrains.rider.model.lambdaDaemonModel
2121
import com.jetbrains.rider.projectView.solution
22+
import software.amazon.awssdk.services.lambda.model.Runtime
2223
import software.aws.toolkits.jetbrains.services.lambda.dotnet.DotNetLambdaHandlerResolver
2324
import software.aws.toolkits.jetbrains.services.lambda.dotnet.element.RiderLambdaHandlerFakePsiElement
2425
import software.aws.toolkits.jetbrains.services.lambda.execution.LambdaRunConfigurationType
@@ -95,8 +96,12 @@ class LambdaDaemonHost(project: Project) : LifetimedProjectComponent(project) {
9596
val configurationType = ConfigurationTypeUtil.findConfigurationType(LambdaRunConfigurationType::class.java)
9697
val runConfigurations = runManager.getConfigurationsList(configurationType)
9798

99+
val isDebug = executor is DefaultDebugExecutor
100+
98101
var settings = runConfigurations.filterIsInstance<LocalLambdaRunConfiguration>().firstOrNull { configuration ->
99-
configuration.handler() == handler
102+
configuration.handler() == handler &&
103+
// TODO: Get rid of the check when SAM CLI provide support for dotnet 3.1 lambda debug
104+
(if (isDebug) configuration.runtime() != Runtime.DOTNETCORE3_1 else true)
100105
}?.let { configuration ->
101106
runManager.findSettings(configuration)
102107
}
@@ -107,7 +112,12 @@ class LambdaDaemonHost(project: Project) : LifetimedProjectComponent(project) {
107112
val template = runManager.getConfigurationTemplate(factory)
108113

109114
val configuration = template.configuration as LocalLambdaRunConfiguration
110-
val runtime = DotNetRuntimeUtils.getCurrentDotNetCoreRuntime()
115+
val activeRuntime = DotNetRuntimeUtils.getCurrentDotNetCoreRuntime()
116+
117+
// TODO: Get rid of the check when SAM CLI provide support for dotnet 3.1 lambda debug
118+
val runtime =
119+
if (isDebug && activeRuntime == Runtime.DOTNETCORE3_1) DotNetRuntimeUtils.defaultDotNetCoreRuntime
120+
else activeRuntime
111121

112122
LocalLambdaRunConfigurationProducer.setAccountOptions(configuration)
113123
configuration.useHandler(runtime, handler)

jetbrains-rider/src/software/aws/toolkits/jetbrains/utils/DotNetRuntimeUtils.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ object DotNetRuntimeUtils {
1313

1414
private val logger = getLogger<DotNetRuntimeUtils>()
1515

16-
val DEFAULT_DOTNET_CORE_RUNTIME: Runtime = Runtime.DOTNETCORE2_1
16+
val defaultDotNetCoreRuntime: Runtime = Runtime.DOTNETCORE2_1
1717

1818
/**
1919
* Get information about current .NET runtime
2020
*
2121
* @return the [software.amazon.awssdk.services.lambda.model.Runtime] instance of current available runtime or
22-
* [DEFAULT_DOTNET_CORE_RUNTIME] value if not defined.
22+
* defaultDotnetCoreRuntime value if not defined.
2323
*/
2424
fun getCurrentDotNetCoreRuntime(): Runtime {
2525
val runtimeList = try {
2626
java.lang.Runtime.getRuntime().exec("dotnet --list-runtimes").inputStream.bufferedReader().readLines()
2727
} catch (e: IOException) {
2828
logger.warn { "Error getting current runtime version: $e" }
29-
return DEFAULT_DOTNET_CORE_RUNTIME
29+
return defaultDotNetCoreRuntime
3030
}
3131

3232
val versionRegex = Regex("(\\d+.\\d+.\\d+)")
@@ -38,10 +38,10 @@ object DotNetRuntimeUtils {
3838
}
3939
.filterNotNull()
4040

41-
val version = versions.maxBy { it } ?: return DEFAULT_DOTNET_CORE_RUNTIME
41+
val version = versions.maxBy { it } ?: return defaultDotNetCoreRuntime
4242

4343
return Runtime.fromValue("dotnetcore${version.split('.').take(2).joinToString(".")}").validOrNull
44-
?: DEFAULT_DOTNET_CORE_RUNTIME
44+
?: defaultDotNetCoreRuntime
4545
}
4646

4747
const val RUNTIME_CONFIG_JSON_21 =

0 commit comments

Comments
 (0)