Skip to content

Commit

Permalink
Improve error messages when properties are not found in templates (#2449
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hunterwerlla committed Feb 19, 2021
1 parent 1458189 commit a1b5417
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Improve error messages when properties are not found in templates (#2449)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package software.aws.toolkits.jetbrains.services.lambda.execution.sam

import com.intellij.execution.ExecutionException
import com.intellij.execution.configurations.RunProfile
import com.intellij.execution.configurations.RunProfileState
import com.intellij.execution.configurations.RunnerSettings
Expand Down Expand Up @@ -137,8 +138,15 @@ class SamInvokeRunner : AsyncProgramRunner<RunnerSettings>() {
}
}
buildWorkflow.onError = {
// Remap to ExecutionException so our run configuration fails properly
// instead of showing up as an IDE Fatal error
val exception = if (it is ExecutionException) {
it
} else {
ExecutionException(it)
}
LOG.warn(it) { "Failed to create Lambda package" }
buildingPromise.setError(it)
buildingPromise.setError(exception)
reportMetric(lambdaSettings, Result.Failed, environment.isDebug())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,23 @@ object SamTemplateUtils {
val function = findFunction(logicalId)
if (function.isServerlessFunction()) {
if (function.isImageBased()) {
function.requiredAt("/Metadata/DockerContext").textValue()
function.getPathOrThrow(logicalId, "/Metadata/DockerContext").textValue()
} else {
function.requiredAt("/Properties/CodeUri").textValue()
function.getPathOrThrow(logicalId, "/Properties/CodeUri").textValue()
}
} else {
function.requiredAt("/Properties/Code").textValue()
function.getPathOrThrow(logicalId, "/Properties/Code").textValue()
}
}

private fun JsonNode.getPathOrThrow(logicalId: String, path: String): JsonNode {
val node = at(path)
if (node.isMissingNode) {
throw RuntimeException(message("cloudformation.key_not_found", path, logicalId))
}
return node
}

private fun JsonNode.findFunction(logicalId: String): JsonNode = this.requiredAt("/Resources").get(logicalId)
?: throw IllegalArgumentException("No resource with the logical ID $logicalId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ cloudformation.execute_change_set.failed=Failed to execute change set against {0
cloudformation.execute_change_set.success=Successfully executed change set against {0}
cloudformation.execute_change_set.success.title=Successfully executed change set
cloudformation.invalid_property=Property {0} has invalid value {1}
cloudformation.key_not_found={0} not found on {1}
cloudformation.key_not_found={0} not found on resource {1}
cloudformation.missing_property=Property {0} not found in {1}
cloudformation.stack.delete.action=Delete Stack...
cloudformation.stack.filter.show_completed=Show Completed
Expand Down

0 comments on commit a1b5417

Please sign in to comment.