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

ExitCodeException loses error messages #337

Closed
drpeck opened this issue Jul 1, 2021 · 7 comments
Closed

ExitCodeException loses error messages #337

drpeck opened this issue Jul 1, 2021 · 7 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@drpeck
Copy link

drpeck commented Jul 1, 2021

Use case(s)

My task is failing during Command.ReadAsync with a NonZeroExitCodeException in production (Docker image running on AWS ECS). It's a nightmare to debug, because the exception doesn't contain the echo'ed text.

Description

ExitCodeException could include the output

Alternatives

We could create Command.TryReadAsync which doesn't through an exception but the return type would state the error code.

@drpeck drpeck added the enhancement New feature or request label Jul 1, 2021
@adamralph
Copy link
Owner

adamralph commented Jul 2, 2021

Hi @drpeck, thanks for raising this.

It sounds like the executable you are running is not well behaved. When it fails, if there is additional diagnostic information about the failure, in addition to the exit code, I would expect that information to be written to stderr, not stdout. Is the source code of the executable under your control? If so, I would first consider changing it to write the diagnostic information to stderr.

@drpeck
Copy link
Author

drpeck commented Jul 3, 2021

It's not under my control unfortunately. TBH I didn't/don't really understand stderr stuff, but I have managed to add a 2> error.log to pipe the errors to a file and I can read it from there.

It would be nice if it were handled all within managed code, but I'm sure it's not straightforward.

Thanks for your hard work.

@adamralph
Copy link
Owner

I see, so it seems that the executable is well behaved, but you are invoking SimpleExec in a context where you don't see stderr in the console.

I need to give this a little more thought. This problem may belong slightly outside the simple contexts that SimpleExec is designed for. I'll get back to you ASAP.

In the meantime, the workaround you are using sounds fine for now.

@adamralph
Copy link
Owner

adamralph commented Jul 4, 2021

BTW, I'm not sure I understand your listed alternative:

We could create Command.TryReadAsync which doesn't through an exception but the return type would state the error code.

It doesn't seem to address the problem you are facing, and it's possible to capture the exit code and swallow the exception today:

string output;
int exitCode;

try
{
    output = Read("foo.exe");
}
catch (ExitCodeException ex) // in 7.x you have to catch NonZeroExitCodeException
{
    exitCode = ex.ExitCode;
}

@drpeck
Copy link
Author

drpeck commented Jul 4, 2021 via email

@adamralph
Copy link
Owner

Well, the exception still doesn't give you the contents of stderr (or stdout). It only gives you the exit code. To be able to see the contents of stderr you need your 2> error.log workaround (or a new feature in SimpleExec).

BTW —

TBH I didn't/don't really understand stderr stuff...

The Wikipedia page has a good explanation.

@adamralph
Copy link
Owner

@drpeck this will covered by #351

Thanks again for raising this.

@adamralph adamralph added the duplicate This issue or pull request already exists label Aug 21, 2021
@adamralph adamralph closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants