dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
969 stars 33 forks source link

Feature request: Print stdout/stderr before throwing #172

Open NfNitLoop opened 11 months ago

NfNitLoop commented 11 months ago

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

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 commented 11 months ago

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.

dsherret commented 11 months ago

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.

sigmaSd commented 10 months ago

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