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

Feature request: Print stdout/stderr before throwing #172

Open
NfNitLoop opened this issue Aug 18, 2023 · 3 comments
Open

Feature request: Print stdout/stderr before throwing #172

NfNitLoop opened this issue Aug 18, 2023 · 3 comments

Comments

@NfNitLoop
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor

sigmaSd commented Aug 26, 2023

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

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

No branches or pull requests

3 participants