Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix async/await exception handling bug in GetExistingStorageAccountAsync #449

Merged
merged 2 commits into from
Aug 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/deploy-cromwell-on-azure/Deployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,24 +1024,36 @@ private Task<IStorageAccount> CreateStorageAccountAsync()
.CreateAsync(cts.Token));

private async Task<IStorageAccount> GetExistingStorageAccountAsync(string storageAccountName)
=> (await Task.WhenAll(subscriptionIds.Select(s =>
=> (await Task.WhenAll(subscriptionIds.Select(async s =>
{
try
{
return azureClient.WithSubscription(s).StorageAccounts.ListAsync();
return await azureClient.WithSubscription(s).StorageAccounts.ListAsync();
}
catch (Exception)
{
// Ignore exception if a user does not have the required role to list storage accounts in a subscription
return null;
}
})))
.SelectMany(a => a)
.Where(a => a is not null)
.SelectMany(a => a)
.SingleOrDefault(a => a.Name.Equals(storageAccountName, StringComparison.OrdinalIgnoreCase) && a.RegionName.Equals(configuration.RegionName, StringComparison.OrdinalIgnoreCase));

private async Task<BatchAccount> GetExistingBatchAccountAsync(string batchAccountName)
=> (await Task.WhenAll(subscriptionIds.Select(s => new BatchManagementClient(tokenCredentials) { SubscriptionId = s }.BatchAccount.ListAsync())))
=> (await Task.WhenAll(subscriptionIds.Select(async s =>
{
try
{
var client = new BatchManagementClient(tokenCredentials) { SubscriptionId = s };
return await client.BatchAccount.ListAsync();
}
catch (Exception)
{
return null;
}
})))
.Where(a => a is not null)
.SelectMany(a => a)
.SingleOrDefault(a => a.Name.Equals(batchAccountName, StringComparison.OrdinalIgnoreCase) && a.Location.Equals(configuration.RegionName, StringComparison.OrdinalIgnoreCase));

Expand Down