Skip to content

Commit 8c814d7

Browse files
committed
Stacks now outputs errors correctly, 2 tests failing
1 parent 8c8713e commit 8c814d7

File tree

6 files changed

+79
-4
lines changed

6 files changed

+79
-4
lines changed

src/Resources/ResourceManager/Implementation/Deployments/GetAzureSubscriptionDeploymentCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected override void OnProcessRecord()
5555
{
5656
DeploymentName = this.Name ?? (string.IsNullOrEmpty(this.Id) ? null : ResourceIdUtility.GetResourceName(this.Id))
5757
};
58-
58+
5959
WriteObject(ResourceManagerSdkClient.FilterDeployments(options), true);
6060
}
6161
}

src/Resources/ResourceManager/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/ResourceManager/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@
469469
<data name="DeploymentOperationOuterError" xml:space="preserve">
470470
<value>The deployment '{0}' failed with error(s). Showing {1} out of {2} error(s).</value>
471471
</data>
472+
<data name="DeploymentStackOperationOuterError" xml:space="preserve">
473+
<value>The deployment '{0}' failed with error(s). Showing {1} out of {2} error(s).</value>
474+
</data>
472475
<data name="DeploymentOperationErrorMessageNoDetails" xml:space="preserve">
473476
<value>{0} (Code:{1})</value>
474477
</data>

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient
2525
{
2626
public class DeploymentStacksSdkClient
2727
{
28+
public const string ErrorFormat = "Error: Code={0}; Message={1}\r\n";
29+
2830
public IDeploymentStacksClient DeploymentStacksClient { get; set; }
2931

3032
public Action<string> VerboseLogger { get; set; }
@@ -369,6 +371,7 @@ string updateBehavior
369371
"Failed",
370372
"Canceled"
371373
);
374+
errorValidation(finalStack);
372375
return new PSDeploymentStack(finalStack);
373376
}
374377

@@ -505,9 +508,31 @@ string deploymentScope
505508
"Canceled"
506509
);
507510

511+
512+
errorValidation(finalStack);
513+
508514
return new PSDeploymentStack(finalStack);
509515
}
510516

517+
private void errorValidation(DeploymentStack deploymentStack)
518+
{
519+
if (deploymentStack.Error != null)
520+
{
521+
var error = deploymentStack.Error;
522+
var sb = new StringBuilder();
523+
List<string> errorMessages = processErrorMessages(error);
524+
sb.AppendFormat(ProjectResources.DeploymentStackOperationOuterError, deploymentStack.Name, errorMessages.Count, errorMessages.Count);
525+
sb.AppendLine();
526+
527+
foreach (string message in errorMessages)
528+
{
529+
sb.AppendLine(message);
530+
}
531+
532+
WriteError(sb.ToString());
533+
}
534+
}
535+
511536
private DeploymentStack waitStackCompletion(Func<Task<AzureOperationResponse<DeploymentStack>>> getStack, params string[] status)
512537
{
513538
//Poll stack deployment based on RetryAfter. If no RetyrAfter is present, polling status in two phases.
@@ -613,6 +638,7 @@ string description
613638
}
614639

615640
var deploymentStack = DeploymentStacksClient.DeploymentStacks.BeginCreateOrUpdateAtResourceGroup(resourceGroupName, deploymentStackName, deploymentStackModel);
641+
errorValidation(deploymentStack);
616642
return new PSDeploymentStack(deploymentStack);
617643
}
618644

@@ -639,5 +665,42 @@ private void WriteError(string error)
639665
ErrorLogger(error);
640666
}
641667
}
668+
669+
private List<string> processErrorMessages(ErrorResponse error)
670+
{
671+
List<string> errorMessages = new List<string>();
672+
673+
Stack<ErrorResponse> stack = new Stack<ErrorResponse>();
674+
stack.Push(error);
675+
676+
while (stack.Count > 0)
677+
{
678+
var currentError = stack.Pop();
679+
errorMessages.Add(string.Format(ErrorFormat, currentError.Code, currentError.Message));
680+
if (currentError.Details != null)
681+
{
682+
foreach (ErrorResponse detail in currentError.Details)
683+
{
684+
stack.Push(detail);
685+
}
686+
}
687+
}
688+
689+
690+
//while length of count of error > 2
691+
//loop through all details
692+
693+
/*while (error.Details != null && error.Details.Count >= 0)
694+
{
695+
errorMessages.Add(string.Format(ErrorFormat, error.Code, error.Message));
696+
if (error.Details.Count == 0)
697+
{
698+
break;
699+
}
700+
error = error.Details[0];
701+
}*/
702+
703+
return errorMessages;
704+
}
642705
}
643706
}

src/Resources/ResourceManager/SdkClient/ResourceManagerSdkClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ private DeploymentExtended ExecuteDeploymentInternal(PSDeploymentCmdletParameter
14691469
this.BeginDeployment(parameters, deployment);
14701470

14711471
WriteVerbose(string.Format(ProjectResources.CreatedDeployment, parameters.DeploymentName));
1472-
1472+
14731473
return ProvisionDeploymentStatus(parameters, deployment);
14741474
}
14751475

src/Resources/ResourceManager/SdkExtensions/ResourcesExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static PSDeployment ToPSDeployment(this DeploymentExtended result, string
6363
{
6464
deployment = CreatePSDeployment(result, managementGroupId, resourceGroupName);
6565
}
66-
66+
6767
return deployment;
6868
}
6969

0 commit comments

Comments
 (0)