Skip to content

Commit 74efcff

Browse files
committed
clarify error messages and format console output
1 parent 625a946 commit 74efcff

File tree

10 files changed

+478
-276
lines changed

10 files changed

+478
-276
lines changed

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzResourceGroupDeploymentStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public override void ExecuteCmdlet()
105105
throw new PSInvalidOperationException(
106106
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
107107
}
108-
TemplateUri = TemplateFile;
108+
TemplateUri = filePath;
109109
break;
110110
case ParameterFileTemplateSpecParameterSetName:
111111
case ParameterFileTemplateUriParameterSetName:
@@ -119,7 +119,7 @@ public override void ExecuteCmdlet()
119119
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
120120
}
121121
parameters = this.GetParameterObject(ParameterFile);
122-
TemplateUri = TemplateFile;
122+
TemplateUri = templatePath;
123123
break;
124124
}
125125

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzSubscriptionDeploymentStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public override void ExecuteCmdlet()
103103
throw new PSInvalidOperationException(
104104
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
105105
}
106-
TemplateUri = TemplateFile;
106+
TemplateUri = filePath;
107107
break;
108108
case ParameterFileTemplateSpecParameterSetName:
109109
case ParameterFileTemplateUriParameterSetName:
@@ -117,7 +117,7 @@ public override void ExecuteCmdlet()
117117
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
118118
}
119119
parameters = this.GetParameterObject(ParameterFile);
120-
TemplateUri = TemplateFile;
120+
TemplateUri = templatePath;
121121
break;
122122
}
123123

src/Resources/ResourceManager/Implementation/DeploymentStacks/RemoveAzSubscriptionDeploymentStack.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public override void ExecuteCmdlet()
3838
{
3939
try
4040
{
41-
ResourceIdentifier resourceIdentifier = (ResourceId != null)
42-
? new ResourceIdentifier(ResourceId)
43-
: null;
44-
4541
Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId);
4642

4743
string confirmationMessage = $"Are you sure you want to remove DeploymentStack '{Name}'";

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzResourceGroupDeploymentStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public override void ExecuteCmdlet()
109109
throw new PSInvalidOperationException(
110110
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
111111
}
112-
TemplateUri = TemplateFile;
112+
TemplateUri = filePath;
113113
break;
114114
case ParameterFileTemplateSpecParameterSetName:
115115
case ParameterFileTemplateUriParameterSetName:
@@ -123,7 +123,7 @@ public override void ExecuteCmdlet()
123123
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
124124
}
125125
parameters = this.GetParameterObject(ParameterFile);
126-
TemplateUri = TemplateFile;
126+
TemplateUri = templatePath;
127127
break;
128128
}
129129

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzSubscriptionDeploymentStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public override void ExecuteCmdlet()
107107
throw new PSInvalidOperationException(
108108
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
109109
}
110-
TemplateUri = TemplateFile;
110+
TemplateUri = filePath;
111111
break;
112112
case ParameterFileTemplateSpecParameterSetName:
113113
case ParameterFileTemplateUriParameterSetName:
@@ -121,7 +121,7 @@ public override void ExecuteCmdlet()
121121
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
122122
}
123123
parameters = this.GetParameterObject(ParameterFile);
124-
TemplateUri = TemplateFile;
124+
TemplateUri = templatePath;
125125
break;
126126
}
127127

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,22 @@ public PSDeploymentStack GetResourceGroupDeploymentStack(
5757
}
5858
catch (Exception ex)
5959
{
60-
if (!throwIfNotExists &&
61-
ex is DeploymentStacksErrorException dex &&
62-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
60+
if (ex is DeploymentStacksErrorException dex)
6361
{
64-
// Deployment Stack does not exist
65-
return null;
62+
if (dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
63+
{
64+
// Deployment Stack does not exist
65+
if (!throwIfNotExists)
66+
return null;
67+
else
68+
throw new PSArgumentException(
69+
$"DeploymentStack '{deploymentStackName}' in Resource Group '{resourceGroupName}' not found."
70+
);
71+
}
72+
else
73+
{
74+
throw new PSArgumentException(dex.Body.Error.Message);
75+
}
6676
}
6777

6878
throw;
@@ -89,15 +99,13 @@ public IEnumerable<PSDeploymentStack> ListResourceGroupDeploymentStack(string re
8999
}
90100
catch (Exception ex)
91101
{
92-
if (!throwIfNotExists &&
93-
ex is DeploymentStacksErrorException dex &&
94-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
95-
{
96-
// Deployment Stack does not exist
102+
if (!throwIfNotExists)
97103
return null;
98-
}
99104

100-
throw;
105+
if (ex is DeploymentStacksErrorException dex)
106+
throw new PSArgumentException(dex.Body.Error.Message);
107+
108+
throw ex;
101109
}
102110
}
103111

@@ -121,15 +129,13 @@ public IEnumerable<PSDeploymentStackSnapshot> ListResourceGroupDeploymentStackSn
121129
}
122130
catch (Exception ex)
123131
{
124-
if (!throwIfNotExists &&
125-
ex is DeploymentStacksErrorException dex &&
126-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
127-
{
128-
// Deployment Stack does not exist
132+
if (!throwIfNotExists)
129133
return null;
130-
}
131134

132-
throw;
135+
if (ex is DeploymentStacksErrorException dex)
136+
throw new PSArgumentException(dex.Body.Error.Message);
137+
138+
throw ex;
133139
}
134140
}
135141

@@ -153,15 +159,13 @@ internal object ListSubscriptionDeploymentStackSnapshot(string stackName, bool t
153159
}
154160
catch (Exception ex)
155161
{
156-
if (!throwIfNotExists &&
157-
ex is DeploymentStacksErrorException dex &&
158-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
159-
{
160-
// Deployment Stack does not exist
162+
if (!throwIfNotExists)
161163
return null;
162-
}
163164

164-
throw;
165+
if (ex is DeploymentStacksErrorException dex)
166+
throw new PSArgumentException(dex.Body.Error.Message);
167+
168+
throw ex;
165169
}
166170
}
167171

@@ -176,12 +180,22 @@ public PSDeploymentStack GetSubscriptionDeploymentStack(string stackName, bool t
176180

177181
catch (Exception ex)
178182
{
179-
if (!throwIfNotExists &&
180-
ex is DeploymentStacksErrorException dex &&
181-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
183+
if (ex is DeploymentStacksErrorException dex)
182184
{
183-
// Deployment Stack does not exist
184-
return null;
185+
if (dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
186+
{
187+
// Deployment Stack does not exist
188+
if (!throwIfNotExists)
189+
return null;
190+
else
191+
throw new PSArgumentException(
192+
$"DeploymentStack '{stackName}' not found in current subscription."
193+
);
194+
}
195+
else
196+
{
197+
throw new PSArgumentException(dex.Body.Error.Message);
198+
}
185199
}
186200

187201
throw;
@@ -208,15 +222,13 @@ public IEnumerable<PSDeploymentStack> ListSubscriptionDeploymentStack(bool throw
208222
}
209223
catch (Exception ex)
210224
{
211-
if (!throwIfNotExists &&
212-
ex is DeploymentStacksErrorException dex &&
213-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
214-
{
215-
// Deployment Stack does not exist
225+
if (!throwIfNotExists)
216226
return null;
217-
}
218227

219-
throw;
228+
if (ex is DeploymentStacksErrorException dex)
229+
throw new PSArgumentException(dex.Body.Error.Message);
230+
231+
throw ex;
220232
}
221233
}
222234

@@ -230,12 +242,22 @@ public PSDeploymentStackSnapshot GetResourceGroupDeploymentStackSnapshot(string
230242

231243
catch (Exception ex)
232244
{
233-
if (!throwIfNotExists &&
234-
ex is DeploymentStacksErrorException dex &&
235-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
245+
if (ex is DeploymentStacksErrorException dex)
236246
{
237-
// Deployment Stack does not exist
238-
return null;
247+
if (dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
248+
{
249+
// Deployment Stack does not exist
250+
if (!throwIfNotExists)
251+
return null;
252+
else
253+
throw new PSArgumentException(
254+
$"DeploymentStackSnapshot '{snapshotName}' of DeploymentStack '{stackName}' in Resource Group '{resourceGroupName}' not found.."
255+
);
256+
}
257+
else
258+
{
259+
throw new PSArgumentException(dex.Body.Error.Message);
260+
}
239261
}
240262

241263
throw;
@@ -252,12 +274,22 @@ public PSDeploymentStackSnapshot GetSubscriptionDeploymentStackSnapshot(string s
252274
}
253275
catch (Exception ex)
254276
{
255-
if (!throwIfNotExists &&
256-
ex is DeploymentStacksErrorException dex &&
257-
dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
277+
if (ex is DeploymentStacksErrorException dex)
258278
{
259-
// Deployment Stack does not exist
260-
return null;
279+
if (dex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
280+
{
281+
// Deployment Stack does not exist
282+
if (!throwIfNotExists)
283+
return null;
284+
else
285+
throw new PSArgumentException(
286+
$"DeploymentStackSnapshot '{snapshotName}' of DeploymentStack '{stackName}' not found in current subscription."
287+
);
288+
}
289+
else
290+
{
291+
throw new PSArgumentException(dex.Body.Error.Message);
292+
}
261293
}
262294

263295
throw;

src/Resources/ResourceManager/SdkModels/DeploymentStacks/PSDeploymentStack.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PSDeploymentStack
1919

2020
public string type { get; set; }
2121

22-
public DateTime? creationTime { get; set; }
22+
public SystemData systemData { get; set; }
2323

2424
public string location { get; set; }
2525

@@ -56,7 +56,8 @@ internal PSDeploymentStack(DeploymentStack deploymentStack)
5656
this.id = deploymentStack.Id;
5757
this.name = deploymentStack.Name;
5858
this.type = deploymentStack.Type;
59-
this.creationTime = (deploymentStack.SystemData != null) ? deploymentStack.SystemData.CreatedAt : null;
59+
this.systemData = deploymentStack.SystemData;
60+
this.updateBehavior = deploymentStack.UpdateBehavior;
6061
this.location = deploymentStack.Location;
6162
this.template = deploymentStack.Template;
6263
this.templateLink = deploymentStack.TemplateLink;

src/Resources/ResourceManager/SdkModels/DeploymentStacks/PSDeploymentStackSnapshot.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class PSDeploymentStackSnapshot
1515

1616
public string type { get; set; }
1717

18-
public DateTime? creationTime { get; set; }
18+
public SystemData systemData { get; set; }
1919

2020
public object template { get; set; }
2121

@@ -54,7 +54,8 @@ internal PSDeploymentStackSnapshot(DeploymentStackSnapshot deploymentStackSnapsh
5454
this.id = deploymentStackSnapshot.Id;
5555
this.name = deploymentStackSnapshot.Name;
5656
this.type = deploymentStackSnapshot.Type;
57-
this.creationTime = deploymentStackSnapshot.SystemData.CreatedAt;
57+
this.systemData = deploymentStackSnapshot.SystemData;
58+
this.updateBehavior = deploymentStackSnapshot.UpdateBehavior;
5859
this.template = deploymentStackSnapshot.Template;
5960
this.templateLink = deploymentStackSnapshot.TemplateLink;
6061
this.parameters = deploymentStackSnapshot.Parameters;

0 commit comments

Comments
 (0)