enhanced error message details

This commit is contained in:
Jorge Cotillo 2019-08-16 20:02:03 -07:00
Родитель feeef75153
Коммит cb084c16b9
2 изменённых файлов: 64 добавлений и 52 удалений

Просмотреть файл

@ -14,8 +14,9 @@ Class AzureResourceManagerDeploymentService: IDeploymentService {
[string] $deploymentParameters, `
[string] $location) {
# call arm deployment
$deployment = `
try {
# call arm deployment
$deployment = `
$this.InvokeARMOperation(
$tenantId,
$subscriptionId,
@ -24,27 +25,31 @@ Class AzureResourceManagerDeploymentService: IDeploymentService {
$deploymentParameters,
$location,
"deploy");
# retrieve the state of the resource and return state and deployment id that is
# generated by arm
# if it fails, throw an exception
$resourceState = `
$this.RetrieveDeploymentData(
$deployment.Id,
$deployment.Name,
$resourceGroupName,
$subscriptionId,
$this.isSubscriptionDeployment);
$resourceState += @{
TenantId = $tenantId
SubscriptionId = $subscriptionId
ResourceGroupName = $resourceGroupName
DeploymentTemplate = ConvertFrom-Json $deploymentTemplate -Depth 100
DeploymentParameters = ConvertFrom-Json $deploymentParameters -Depth 100
# retrieve the state of the resource and return state and deployment id that is
# generated by arm
# if it fails, throw an exception
$resourceState = `
$this.RetrieveDeploymentData(
$deployment.Id,
$deployment.Name,
$resourceGroupName,
$subscriptionId,
$this.isSubscriptionDeployment);
$resourceState += @{
TenantId = $tenantId
SubscriptionId = $subscriptionId
ResourceGroupName = $resourceGroupName
DeploymentTemplate = ConvertFrom-Json $deploymentTemplate -Depth 100
DeploymentParameters = ConvertFrom-Json $deploymentParameters -Depth 100
}
return $resourceState;
}
catch {
throw $(Get-Exeption -ErrorObject $_);
}
return $resourceState;
}
[void] ExecuteValidation([string] $tenantId, `
@ -54,40 +59,45 @@ Class AzureResourceManagerDeploymentService: IDeploymentService {
[string] $deploymentParameters, `
[string] $location) {
# Try to fetch the validation resource group
$validationResourceGroup = `
try {
# Try to fetch the validation resource group
$validationResourceGroup = `
Get-AzResourceGroup `
-Name $resourceGroupName `
-ErrorAction SilentlyContinue;
# Does the validation resource group exists?
if($null -ne $validationResourceGroup) {
# call arm validation
$validation = `
$this.InvokeARMOperation(
$tenantId,
$subscriptionId,
$resourceGroupName,
$deploymentTemplate,
$deploymentParameters,
$location,
"validate");
}
else {
# Fail early if the validation resource group does not
# exists
Throw "Validation resource group - $resourceGroupName is not setup. Create the validation resource `
group before invoking the ARM validation.";
}
# Does the validation resource group exists?
if($null -ne $validationResourceGroup) {
# call arm validation
$validation = `
$this.InvokeARMOperation(
$tenantId,
$subscriptionId,
$resourceGroupName,
$deploymentTemplate,
$deploymentParameters,
$location,
"validate");
}
else {
# Fail early if the validation resource group does not
# exists
Throw "Validation resource group - $resourceGroupName is not setup. Create the validation resource `
group before invoking the ARM validation.";
}
# Did the validation succeed?
if($validation.error.code -eq "InvalidTemplateDeployment") {
# Throw an exception and pass the exception message from the
# ARM validation
Throw ("Validation failed with the error below: {0}" -f (ConvertTo-Json $validation -Depth 50));
# Did the validation succeed?
if($validation.error.code -eq "InvalidTemplateDeployment") {
# Throw an exception and pass the exception message from the
# ARM validation
Throw ("Validation failed with the error below: {0}" -f (ConvertTo-Json $validation -Depth 50));
}
else {
Write-Host "Validation Passed";
}
}
else {
Write-Host "Validation Passed";
catch {
throw $(Get-Exeption -ErrorObject $_);
}
}

Просмотреть файл

@ -420,8 +420,10 @@ Function New-Deployment {
}
catch {
Write-Host "An error ocurred while running New-Deployment";
Write-Host $_;
throw $_;
$errorMessage = `
$(Get-Exeption -ErrorObject $_);
Write-Host $errorMessage;
throw $errorMessage;
}
}