puppetlabs / ruby-pwsh

A ruby gem for interacting with PowerShell
MIT License
15 stars 23 forks source link

Error handling #336

Open mato opened 3 weeks ago

mato commented 3 weeks ago

This may not be a bug, I'm not a Powershell expert, but I don't know where else to ask:

Is there a way to reliably ensure that I get a clear indication on the Ruby side, when the Powershell command invoked by execute() results in an error or exception?

Trivial example:

irb(main):031:0> pwsh.execute('errorerrorerror')
=> 
{:exitcode=>0,
 :errormessage=>nil,
 :stderr=>[],
 :stdout=>
  "errorerrorerror: The term 'errorerrorerror' is not recognized as a name of a cmdlet, function, script file, or executable program.\nCheck the spelling of the name, or if a path was included, verify that the path is correct and try again.\n",
 :native_stdout=>nil}

I'd expect to get at least an :exitcode of 1, or any of :errormessage, :stderr populated. Instead, I get nothing, and the error text just shows up in :stdout.

If type errorerrorerror into an interactive pwsh session on Linux, then the error message is in red, so I'm assuming that Powershell "knows" it's an error?

Context: I'm trying to automate a bunch of Exchange maintenance using the EXOv3 Powershell module, but driving "what needs to be done" from a Ruby script, which connects to a bunch of other systems. If I get my EXOv3 invocations wrong, I get no indication on the Ruby side that the command(s) failed.

jordanbreen28 commented 17 hours ago

hey @mato, we are going to add an action item to investigate this. Could you supply us with some reproduction steps to get us up and running quicker? Thanks.