Skip to content

Commit e69e0c2

Browse files
authored
Improved the error message of Az.KeyVault.Extension (Azure#16815)
1 parent 2f17df7 commit e69e0c2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/KeyVault/KeyVault/Az.KeyVault.Extension/Az.KeyVault.Extension.psm1

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44
function Check-SubscriptionLogIn
55
{
66
param (
7-
[string] $SubscriptionId,
8-
[string] $AzKVaultName
7+
[object] $SubscriptionId,
8+
[object] $AzKVaultName
99
)
1010

11+
if("string" -ne $SubscriptionId.GetType().Name)
12+
{
13+
throw "The type of SubscriptionId should be string, current is " + $SubscriptionId.GetType().Name + ". Please check registration information by 'Get-SecretVault | fl'"
14+
}
15+
16+
if("string" -ne $AzKVaultName.GetType().Name)
17+
{
18+
throw "The type of AzKVaultName should be string, current is " + $AzKVaultName.GetType().Name + ". Please check registration information by 'Get-SecretVault | fl'"
19+
}
20+
1121
$azContext = Az.Accounts\Get-AzContext
12-
if (($azContext -eq $null) -or ($azContext.Subscription.Id -ne $SubscriptionId))
22+
if (($null -eq $azContext) -or ($azContext.Subscription.Id -ne $SubscriptionId))
1323
{
1424
try
1525
{
1626
Set-AzContext -SubscriptionId ${SubscriptionId} -ErrorAction Stop
1727
}
1828
catch
1929
{
20-
throw "To use ${AzKVaultName} Azure vault, the current user must be logged into Azure account subscription ${SubscriptionId}. Run 'Connect-AzAccount -SubscriptionId ${SubscriptionId}'."
30+
throw $_.ToString() + "To use Azure vault named '${AzKVaultName}', please try 'Connect-AzAccount -SubscriptionId {SubscriptionId}' to log into Azure account subscription '${SubscriptionId}'."
2131
}
2232
}
2333
}
@@ -33,7 +43,7 @@ function Get-Secret
3343
Check-SubscriptionLogIn $AdditionalParameters.SubscriptionId $AdditionalParameters.AZKVaultName
3444

3545
$secret = Az.KeyVault\Get-AzKeyVaultSecret -Name $Name -VaultName $AdditionalParameters.AZKVaultName
36-
if ($secret -ne $null)
46+
if ($null -ne $secret)
3747
{
3848
switch ($secret.ContentType) {
3949
'ByteArray'

src/KeyVault/KeyVault/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Improved the error message of Az.KeyVault.Extension [#16798]
2122
* Added default access policies for Key Vault key as "All but purge"
2223
* Absorbed KeyOps from parameter when importing key from certificate on managed HSM [#16773]
2324
* Fixed a bug when updating key operations on managed HSM [#16774]

0 commit comments

Comments
 (0)