-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Comments
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. |
It's not under my control unfortunately. TBH I didn't/don't really understand stderr stuff, but I have managed to add a 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. |
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. |
BTW, I'm not sure I understand your listed alternative:
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;
} |
I suppose I had assumed at the time that the output wasn't returned at all with a non-zero, rather than it was possible to capture as you have above.
…________________________________
From: Adam Ralph ***@***.***>
Sent: Sunday, July 4, 2021 7:22:39 AM
To: adamralph/simple-exec ***@***.***>
Cc: David Peck ***@***.***>; Mention ***@***.***>
Subject: Re: [adamralph/simple-exec] ExitCodeException loses error messages (#337)
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 result;
int exitCode;
try
{
result = Read("foo.exe");
}
catch (ExitCodeException ex) // in 7.x you have to catch NonZeroExitCodeException
{
exitCode = ex.ExitCode;
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#337 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAJEAD5K5ZI3V4OU7GVTAOTTV7427ANCNFSM47UGX7LA>.
|
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 BTW —
The Wikipedia page has a good explanation. |
Use case(s)
My task is failing during
Command.ReadAsync
with aNonZeroExitCodeException
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 outputAlternatives
We could create
Command.TryReadAsync
which doesn't through an exception but the return type would state the error code.The text was updated successfully, but these errors were encountered: