Skip to content

Commit 1559dc7

Browse files
committed
Small fixes
1 parent 2959e5f commit 1559dc7

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Components/LongRunningOperationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ internal string WaitOnOperation(OperationResult operationResult)
8383

8484
var trackingResult = this.HandleOperationResponse(operationResult, this.IsResourceCreateOrUpdate ? operationResult.OperationUri : operationResult.LocationUri);
8585

86-
while (trackingResult.ShouldWait)
86+
while (trackingResult != null && trackingResult.ShouldWait)
8787
{
8888
operationResult =
8989
this.GetResourcesClient()

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Extensions/ErrorResponseMessageExceptionExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions
1616
{
17+
using System;
1718
using System.Management.Automation;
1819
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses;
1920

@@ -31,5 +32,25 @@ internal static ErrorRecord ToErrorRecord(this ErrorResponseMessageException exc
3132
// TODO: Improve this.
3233
return new ErrorRecord(exception, exception.ErrorResponseMessage == null ? exception.HttpStatus.ToString() : exception.ErrorResponseMessage.Error.Code, ErrorCategory.CloseError, null);
3334
}
35+
36+
/// <summary>
37+
/// Converts <see cref="Exception"/> objects into <see cref="ErrorRecord"/>
38+
/// </summary>
39+
/// <param name="exception">The exception</param>
40+
internal static ErrorRecord ToErrorRecord(this Exception exception)
41+
{
42+
// TODO: Improve this.
43+
return new ErrorRecord(exception, exception.Message, ErrorCategory.CloseError, null);
44+
}
45+
46+
/// <summary>
47+
/// Converts <see cref="AggregateException"/> objects into <see cref="ErrorRecord"/>
48+
/// </summary>
49+
/// <param name="exception">The exception</param>
50+
internal static ErrorRecord ToErrorRecord(this AggregateException aggregateException)
51+
{
52+
// TODO: Improve this.
53+
return new ErrorRecord(aggregateException, aggregateException.ToString(), ErrorCategory.CloseError, null);
54+
}
3455
}
3556
}

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Extensions/JsonExtensions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,16 @@ public static bool CanConvertTo<TType>(this JToken jobject)
155155
/// <param name="result">The result.</param>
156156
public static bool TryConvertTo<TType>(this string str, out TType result)
157157
{
158-
JToken tmp = null;
158+
if (string.IsNullOrWhiteSpace(str))
159+
{
160+
result = default(TType);
161+
return true;
162+
}
163+
159164
try
160165
{
161-
tmp = str.ToJToken();
166+
result = str.FromJson<TType>();
167+
return !object.Equals(result, default(TType));
162168
}
163169
catch (FormatException)
164170
{
@@ -170,7 +176,8 @@ public static bool TryConvertTo<TType>(this string str, out TType result)
170176
{
171177
}
172178

173-
return tmp.TryConvertTo<TType>(out result);
179+
result = default(TType);
180+
return false;
174181
}
175182

176183
/// <summary>

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Implementation/ResourceManagerCmdletBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,12 @@ private void HandleException(ExceptionDispatchInfo capturedException)
344344
{
345345
this.ThrowTerminatingError(errorResponseException.ToErrorRecord());
346346
}
347+
348+
this.ThrowTerminatingError(aggregateException.InnerExceptions.Single().ToErrorRecord());
347349
}
348350
else
349351
{
350-
throw aggregateException.Flatten();
352+
this.ThrowTerminatingError(aggregateException.ToErrorRecord());
351353
}
352354
}
353355

0 commit comments

Comments
 (0)