dax icon indicating copy to clipboard operation
dax copied to clipboard

Feature request: Print stdout/stderr before throwing

Open NfNitLoop opened this issue 2 years ago • 3 comments

If I'm running a command with .quiet() or .stdout("piped").stderr("piped") and it fails, I just get an error like this:

error: Uncaught (in promise) Error: Exited with code: 1
            throw new Error(`Exited with code: ${code}`);

This makes it a bit of a pain to debug commands that start to fail for some reason.

I'm about to write a function for myself to

  • run the command with .noThrow()
  • check its result.
  • If the result != 0, print out its stdout/stderr
  • Then throw an error about the return code.

But it would be nice if this were built-in!

My preference would be for this to be on by default in cases where stderr/stdout are being suppressed. But that might have performance implications for .quiet() which I'm guessing just sends outputs to /dev/null. So maybe opt-in? .debugThrow()? showThrow()?

NfNitLoop avatar Aug 18 '23 01:08 NfNitLoop

Let me know if you'd be open to a PR here (and if you have preferences w/ the approach). I'd be interested in writing this up.

NfNitLoop avatar Aug 18 '23 16:08 NfNitLoop

I'm not sure at the moment that another method should be added for this that's built in because I think how it should be handled is probably specific to the scenario. For example, the output of stderr might be quite large or the script might only show useful information on stdout for some reason. Also, since the output is piped, it might have been consumed by something else already.

Perhaps when the error is thrown it should also include the CommandChild and using that error someone could get the output on failure. Overall, it's a good suggestion, but it might be good to sit on this one for a bit.

dsherret avatar Aug 18 '23 21:08 dsherret

when I get an error with dax, I usually just add $.setPrintCommand(true); at the top of the file, currently that's the best workaround available

sigmaSd avatar Aug 26 '23 18:08 sigmaSd