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

TFailure of PsCmdletResult<TSuccess, TFailure> is not returned on errors #86

Open
nightroman opened this issue Aug 3, 2017 · 0 comments

Comments

@nightroman
Copy link

In the following script

    #I @"packages\FSharp.Management\lib\net40"
    #r "FSharp.Management.PowerShell.dll"
    #r "System.Management.Automation"

    open FSharp.Management
    open System.Management.Automation

    type PS = PowerShellProvider< "Microsoft.PowerShell.Management;Microsoft.PowerShell.Core" >

    PS.``Get-Variable`` (name=[|"Host"|])
    |> printfn "%A"

    PS.``Get-Variable`` (name=[|"Missing"|])
    |> printfn "%A"

    PS.``Get-Variable`` (name=[|"Missing"|], errorAction=ActionPreference.Stop)
    |> printfn "%A"

the type of PS.``Get-Variable`` is PsCmdletResult<List<PSVariable>,List<ErrorRecord>>.

The script makes three calls:

  1. Get-Variable returns a variable, the result is Success [System.Management.Automation.PSVariable].
  2. Get-Variable writes a non-terminating error, the result is Success [].
  3. Get-Variable writes a terminating error, this results in an exception.
    [Loading ...\TestError.fsx]

    Success [System.Management.Automation.PSVariable]

    Success []

    System.Management.Automation.ActionPreferenceStopException: The running command
    stopped because the preference variable "ErrorActionPreference" or common
    parameter is set to Stop: Cannot find a variable with the name 'Missing'.
    ...

    Stopped due to error

Thus, TFailure of PsCmdletResult<TSuccess, TFailure> is never used.

Is this a bug? What is the expected result in (2) and (3), by design?

The design of the result type is not clear, though. It does not cover all
possible cases, for example a case when a command writes both data and
errors, e.g. with existing and missing variables specified at the same
time on Get-Variable calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants