Skip to content

Commit 1884551

Browse files
null check.
1 parent a0aabba commit 1884551

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/ResourceManager/Common/Commands.Common.Strategies/Extensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public static TValue GetOrNull<TKey, TValue>(
3434
this IDictionary<TKey, TValue> dictionary, TKey key)
3535
where TValue : class
3636
{
37+
if (key == null)
38+
{
39+
return null;
40+
}
3741
TValue result;
3842
dictionary.TryGetValue(key, out result);
3943
return result;

src/ResourceManager/Common/Commands.Common.Strategies/GetStateExtensions.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ static async Task GetStateAsync<TModel>(
4747
this StateOperationContext context, ResourceConfig<TModel> config)
4848
where TModel : class
4949
=> await context.GetOrAdd(
50-
config,
51-
async () =>
50+
config,
51+
async () =>
52+
{
53+
var info = await config.GetAsync(context.Client, context.CancellationToken);
54+
// Get state of dependencies if the resource doesn't exist
55+
if (info == null)
5256
{
53-
var info = await config.GetAsync(context.Client, context.CancellationToken);
54-
// Get state of dependencies if the resource doesn't exist
55-
if (info == null)
56-
{
57-
var tasks = config
58-
.GetResourceDependencies()
59-
.Select(context.GetStateAsyncDispatch);
60-
await Task.WhenAll(tasks);
61-
}
62-
return info;
63-
});
57+
var tasks = config
58+
.GetResourceDependencies()
59+
.Select(context.GetStateAsyncDispatch);
60+
await Task.WhenAll(tasks);
61+
}
62+
return info;
63+
});
6464

6565
sealed class GetStateAsyncVisitor : IResourceConfigVisitor<StateOperationContext, Task>
6666
{

src/ResourceManager/Common/Commands.Common.Strategies/State.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ readonly ConcurrentDictionary<string, object> _Map
2727

2828
public TModel Get<TModel>(ResourceConfig<TModel> config)
2929
where TModel : class
30-
=> _Map.GetOrNull(config.DefaultIdStr()) as TModel;
30+
=> _Map.GetOrNull(config?.DefaultIdStr()) as TModel;
3131

3232
public TModel GetOrAdd<TModel>(ResourceConfig<TModel> config, Func<TModel> f)
3333
where TModel : class

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
402402

403403
if (target.Get(availabilitySet) != null)
404404
{
405-
throw new CloudException("Availability set doesn't exsist.");
405+
throw new InvalidOperationException("Availability set doesn't exist.");
406406
}
407407

408408
// apply target state

0 commit comments

Comments
 (0)