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

[BUG] "Exception has been thrown by the target of an invocation" instead of real error #2818

Closed
fowl2 opened this issue Feb 14, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request reproduced Issue reproduced after testing

Comments

@fowl2
Copy link
Contributor

fowl2 commented Feb 14, 2023

Background: My client secret has expired.

Expected behavior

In SharePointPnPPowerShellOnline, Connect-PnPOnline will return an error 'Token request failed', with exception details available^ .

^ eg, the slightly unwieldy, but possible:

> [System.IO.StreamReader]::new($Error[0].Exception.InnerException.Response.GetResponseStream()).ReadToEnd()

{"error":"invalid_client","error_description":"AADSTS7000222: The provided client secret keys for app 'xxx' are expired. Visit the Azure portal to create new keys for your app: https://aka.ms/NewClientSecret, or consider using certificate credentials for added security: https://aka.ms/certCreds.\r\nTrace ID: xxxx\r\nCorrelation ID: yyy\r\nTimestamp: 2023-02-14 08:32:27Z","error_codes":[7000222],"timestamp":"2023-02-14 08:32:27Z","trace_id":"xxx","correlation_id":"yyy","error_uri":"https://accounts.accesscontrol.windows.net/error?code=7000222"}

Actual behavior

In PnP.PowerShell version 1.12.0, Get-PnPList (and others) will return "Exception has been thrown by the target of an invocation." with no information about what the actual problem is.

Steps to reproduce behavior

Connect-PnPOnline -ClientSecret 'xxxx' -ClientId 'yyyy' -Url https://xxx.sharepoint.com/sites/yyy/'
Get-PnPList

Platform

Name                           Value                                                                                                                           
----                           -----                                                                                                                           
PSVersion                      5.1.19041.2364                                                                                                                  
PSEdition                      Desktop                                                                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                         
BuildVersion                   10.0.19041.2364                                                                                                                 
CLRVersion                     4.0.30319.42000                                                                                                                 
WSManStackVersion              3.0                                                                                                                             
PSRemotingProtocolVersion      2.3                                                                                                                             
SerializationVersion           1.1.0.1          

I guess I can understand getting the access token "lazily" (on the first cmdlet that requires it), but not including any details of the error makes it really difficult to debug problems

@fowl2 fowl2 added the bug Something isn't working label Feb 14, 2023
@Clam-
Copy link

Clam- commented Feb 15, 2023

I also ran in to this issue, however I was unable to get the "slightly unwieldy, but possible" output to work. Probably because it may vary depending on the call made.
After extending the expiry date of my secret I no longer get those ambiguous errors.

@KoenZomers KoenZomers self-assigned this Feb 16, 2023
@KoenZomers KoenZomers added reproduced Issue reproduced after testing enhancement New feature or request and removed bug Something isn't working labels Feb 16, 2023
@KoenZomers
Copy link
Collaborator

Good idea! I've added better handling of the returned error:

image

@Clam-
Copy link

Clam- commented Feb 16, 2023

@KoenZomers Great! Thanks so much for adding this!

@gautamdsheth
Copy link
Collaborator

Closing this , fixed via #2828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request reproduced Issue reproduced after testing
Projects
None yet
Development

No branches or pull requests

4 participants