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

Handle $ErrorActionPreference value #4079

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

jackpoz
Copy link
Contributor

@jackpoz jackpoz commented Jul 8, 2024

Type

  • Bug Fix
  • New Feature
  • Sample

Related Issues?

No related issues

What is in this Pull Request ?

Handle $ErrorActionPreference global PowerShell variable in the same way as -ErrorAction cmdlet parameter is handled when throwing exceptions. Documentation about $ErrorActionPreference at https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.4#erroractionpreference

$ErrorActionPreference = 'Stop' can be put on top of scripts and it will change the behavior of ErrorAction for the whole PowerShell session.

Behavior before this change. Notice how the callstack shows the generic PnPConnectedCmdlet.ProcessRecord() method:
image

Behavior after this change. Notice how Get-PnPException shows the full callstack including GetList.ExecuteCmdlet() :
image

-ErrorAction:Stop cmdlet parameter still works:
image

-ErrorAction:Stop also takes precedence over $ErrorActionPreference:
image

jackpoz and others added 2 commits July 8, 2024 22:44
Handle $ErrorActionPreference in the same way as -ErrorAction cmdlet parameter is handled
@gautamdsheth gautamdsheth merged commit 0b8ae41 into pnp:dev Aug 9, 2024
2 checks passed
@gautamdsheth
Copy link
Collaborator

Thanks @jackpoz , great addition, much appreciated !

@jackpoz jackpoz deleted the fixes/ErrorActionPreference branch August 10, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants