SecretManagement.PleasantPasswordServer.Extension/Private/Write-VaultError.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Write-VaultError
{
    param
    (
        [Parameter(Mandatory)]
        [System.Management.Automation.ErrorRecord]
        $ErrorRecord
    )

    <#
    .SYNOPSIS
    Takes a terminating error and first writes it as a non-terminating error to the user to better surface the issue.
    .NOTES
    This was taken from Justin Grote and his Keepass extension https://github.com/JustinGrote/SecretManagement.KeePass
    #>


    $lastErrorActionPreference = $ErrorActionPreference
    $ErrorActionPreference = 'Continue'
    Write-Error -Message "Vault ${VaultName}: $($ErrorRecord.Exception.Message)"
    $ErrorActionPreference = $lastErrorActionPreference
    throw $ErrorRecord
}