Skip to content

Commit 1f373a5

Browse files
authored
Merge pull request Azure#10580 from VeryEarly/nullreferenceexception-in-GetAzLocation#10575
handle null reference in get-azlocation when no subscription under current directory
2 parents 77483f2 + 9c03407 commit 1f373a5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/Resources/ResourceManager/Implementation/Locations/GetAzureLocationCmdlet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2222
using System.Collections.Generic;
2323
using System.Linq;
2424
using System.Management.Automation;
25+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties;
2526

2627
/// <summary>
2728
/// Get all locations with the supported providers.
@@ -34,6 +35,10 @@ public class GetAzureLocationCmdlet : ResourceManagerCmdletBase
3435
/// </summary>
3536
public override void ExecuteCmdlet()
3637
{
38+
if(DefaultContext.Subscription == null)
39+
{
40+
throw new PSInvalidOperationException(Resources.NoSubscriptionsUnderCurrentDirectory);
41+
}
3742
var allLocations = this.SubscriptionSdkClient.ListLocations(DefaultContext.Subscription.Id.ToString());
3843
var providers = this.ResourceManagerSdkClient.ListResourceProviders(providerName: null, listAvailable: true);
3944
var providerLocations = ConstructResourceProviderLocations(allLocations, providers);

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,7 @@
423423
<data name="InvalidFilePath" xml:space="preserve">
424424
<value>The provided file {0} doesn't exist</value>
425425
</data>
426-
</root>
426+
<data name="NoSubscriptionsUnderCurrentDirectory" xml:space="preserve">
427+
<value>No subscriptions can be found under current directory. Please login again using Connect-AzAccount.</value>
428+
</data>
429+
</root>

0 commit comments

Comments
 (0)