Skip to content

Handle $ErrorActionPreference value#4079

Merged
gautamdsheth merged 2 commits intopnp:devfrom
jackpoz:fixes/ErrorActionPreference
Aug 9, 2024
Merged

Handle $ErrorActionPreference value#4079
gautamdsheth merged 2 commits intopnp:devfrom
jackpoz:fixes/ErrorActionPreference

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
@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