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

WhatIf issues on Invoke-AzRestMethod #26693

Open
jikuja opened this issue Nov 14, 2024 · 0 comments
Open

WhatIf issues on Invoke-AzRestMethod #26693

jikuja opened this issue Nov 14, 2024 · 0 comments
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team.

Comments

@jikuja
Copy link

jikuja commented Nov 14, 2024

Description

Invoke-AzRestMethod throws non-descriptive error when using -WhatIf

Invoke-AzRestMethod -Method "PATCH" -Uri "https://graph.microsoft.com/beta/groups/f686f775-adf2-4c11-902f-7f62449bdaf9" -Payload '{"description": "uli"}' -WhatIf

Invoke-AzRestMethod: Object reference not set to an instance of an object.


CmdLet should give clear description if -WhatIf is not supported instead of throwing error by null access fault.

Issue script & Debug output

PS /home/janne> Invoke-AzRestMethod -Method "PATCH" -Uri "https://graph.microsoft.com/beta/groups/f686f775-adf2-4c11-902f-7f62449bdaf9" -Payload '{"description": "uli"}' -WhatIf
DEBUG: 4:37:52 PM - [ConfigManager] Got [True] from [DisplaySecretsWarning], Module = [], Cmdlet = [].
DEBUG: 4:37:52 PM - InvokeAzRestMethodCommand begin processing with ParameterSet 'ByURI'.
DEBUG: 4:37:52 PM - using account id 'MSI@50342'...
DEBUG: 4:37:52 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: [Common.Authentication]: Authenticating using Account: 'MSI@50342', environment: 'AzureCloud', tenant: '0a8edbb9-667f-4120-88fd-2cd241f8236f'
DEBUG: 4:37:52 PM - [ConfigManager] Got nothing from [DisableInstanceDiscovery], Module = [], Cmdlet = []. Returning default value [False].
What if: Performing the operation "PATCH" on target "/beta/groups/f686f775-adf2-4c11-902f-7f62449bdaf9".
DEBUG: 4:37:52 PM - [ManagedServiceIdentityAuthenticator] Calling ManagedIdentityCredential.GetTokenAsync - TenantId:'0a8edbb9-667f-4120-88fd-2cd241f8236f', Scopes:'https://graph.microsoft.com/', UserId:''
DEBUG: ManagedIdentityCredential.GetToken invoked. Scopes: [ https://graph.microsoft.com/ ] ParentRequestId: 
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] MSAL MSAL.CoreCLR with assembly version '4.61.3.0'. CorrelationId(9023656d-3085-4250-ba3f-ddcc1f077139)
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] === AcquireTokenForClientParameters ===
SendX5C: False
ForceRefresh: False

DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] 
=== Request Data ===
Authority Provided? - True
Scopes - https://graph.microsoft.com/
Extra Query Params Keys (space separated) - 
ApiId - AcquireTokenForClient
IsConfidentialClient - True
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - 9023656d-3085-4250-ba3f-ddcc1f077139
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured: 

DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] === Token Acquisition (ClientCredentialRequest) started:
         Scopes: https://graph.microsoft.com/
        Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] [Region discovery] Not using a regional authority. 
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] [Instance Discovery] Skipping Instance discovery because it is disabled. 
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] [ClientCredentialRequest] Acquiring a token from the token provider.
DEBUG: Request [62614fb8-11d6-455f-b4a3-1eb7c2e9a48b] POST http://localhost:50342/oauth2/token
Content-Type:application/x-www-form-urlencoded
Metadata:REDACTED
x-ms-client-request-id:62614fb8-11d6-455f-b4a3-1eb7c2e9a48b
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.12.0 (.NET 8.0.8; CBL-Mariner/Linux)
client assembly: Azure.Identity
DEBUG: Response [62614fb8-11d6-455f-b4a3-1eb7c2e9a48b] 200 OK (00.0s)
X-Powered-By:REDACTED
ETag:W/"a18-TO2HnCHzIkVkXHCjFwSFuEWGoqk"
Date:Thu, 14 Nov 2024 16:37:52 GMT
Connection:keep-alive
Keep-Alive:REDACTED
Content-Type:application/json; charset=utf-8
Content-Length:2584

DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] Checking client info returned from the server..
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] Saving token response to cache..
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] [SaveTokenResponseAsync] ID Token not present in response. 
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] Cannot determine home account ID - or id token or no client info and no subject 
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] [SaveTokenResponseAsync] Saving AT in cache and removing overlapping ATs...
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] Looking for scopes for the authority in the cache which intersect with https://graph.microsoft.com/
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] Intersecting scope entries count - 0
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] 
        === Token Acquisition finished successfully:
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139]  AT expiration time: 11/14/2024 5:49:00 PM +00:00, scopes: https://graph.microsoft.com/. source: IdentityProvider
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.8 Linux [2024-11-14 16:37:52Z - 9023656d-3085-4250-ba3f-ddcc1f077139] Fetched access token from host login.microsoftonline.com. 
DEBUG: ManagedIdentityCredential.GetToken succeeded. Scopes: [ https://graph.microsoft.com/ ] ParentRequestId:  ExpiresOn: 2024-11-14T17:49:00.4048823+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '0a8edbb9-667f-4120-88fd-2cd241f8236f', UserId: 'MSI@50342'
DEBUG: 4:37:52 PM - [ConfigManager] Got nothing from [EnableErrorRecordsPersistence], Module = [], Cmdlet = []. Returning default value [False].
Invoke-AzRestMethod: Object reference not set to an instance of an object.
DEBUG: 4:37:52 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 4:37:52 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 4:37:52 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent:  Module: Az.Accounts:3.0.4; CommandName: Invoke-AzRestMethod; PSVersion: 7.4.5; IsSuccess: False; Duration: 00:00:00.1805695; SanitizeDuration: 00:00:00; Exception: Object reference not set to an instance of an object.;
DEBUG: 4:37:52 PM - [ConfigManager] Got [True] from [EnableDataCollection], Module = [], Cmdlet = [].
DEBUG: 4:37:52 PM - InvokeAzRestMethodCommand end processing.

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.5
PSEdition                      Core
GitCommitId                    7.4.5
OS                             CBL-Mariner/Linux
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     3.0.4                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDef…
Script     8.4.0                 Az.Compute                          {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendConte…
Script     7.9.0                 Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplic…
Script     7.5.0                 Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssign…
Script     7.4.0                 Az.Storage                          {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManageme…
Script     1.1.3                 Az.Tools.Predictor                  {Disable-AzPredictor, Enable-AzPredictor, Open-AzPredictorSurvey…
Script     0.0.0.10              AzureAD.Standard.Preview            {Add-AzureADApplicationOwner, Add-AzureADDeviceRegisteredOwner, …
Script     0.9.3                 AzurePSDrive

Error output

DEBUG: 4:39:03 PM - [ConfigManager] Got [True] from [DisplaySecretsWarning], Module = [], Cmdlet = [].
DEBUG: 4:39:03 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 4:39:03 PM - using account id 'MSI@50342'...
DEBUG: 4:39:03 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 4:39:03 PM - [ConfigManager] Got [True] from [DisplaySecretsWarning], Module = [], Cmdlet = [].

   HistoryId: 3

Message        : Object reference not set to an instance of an object.
StackTrace     :    at Microsoft.Azure.Commands.Profile.Models.PSHttpResponse..ctor(AzureOperationResponse`1 response)
                    at Microsoft.Azure.Commands.Profile.Rest.InvokeAzRestMethodCommand.ExecuteCmdlet()
                    at 
                 Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, 
                 Action`1 executor)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.NullReferenceException
InvocationInfo : {Invoke-AzRestMethod}
Line           : Invoke-AzRestMethod -Method "PATCH" -Uri 
                 "https://graph.microsoft.com/beta/groups/f686f775-adf2-4c11-902f-7f62449bdaf9" -Payload '{"description": "uli"}' 
                 -WhatIf
Position       : At line:1 char:1
                 + Invoke-AzRestMethod -Method "PATCH" -Uri "https://graph.microsoft.com …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 3



DEBUG: 4:39:03 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 4:39:03 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent:  Module: Az.Accounts:3.0.4; CommandName: Resolve-AzError; PSVersion: 7.4.5; IsSuccess: True; Duration: 00:00:00.0383525; SanitizeDuration: 00:00:00.0008848
DEBUG: 4:39:03 PM - [ConfigManager] Got [True] from [EnableDataCollection], Module = [], Cmdlet = [].
DEBUG: 4:39:03 PM - ResolveError end processing.
@jikuja jikuja added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Nov 14, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team.
Projects
None yet
Development

No branches or pull requests

1 participant