Skip to content

Capture stdout and stderr even if cmd.Run fails #34

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mproffitt
Copy link

@mproffitt mproffitt commented Jan 11, 2025

Description of your changes

In its current form, if cmd.Run fails, then the function immediately exits with no reason given for the termination. This makes debugging scripts hard to understand as no indication is given for the failure, other than a failure occured.

By trapping the error returned from cmd.Run, we first process the buffers for both stdout and stderr and set these to the dxr.

Additionally we capture a truncated stderr from the command error which can help point to where the command failed, setting this as the Fatal error message returned as an event.

Both stderr and stdout are also pushed to the debug log before returning fatal on error to ensure all information available to the function is also available to the end user for debugging purposes.

I have:

@mproffitt mproffitt marked this pull request as draft January 11, 2025 10:16
@mproffitt mproffitt force-pushed the rework-shell-execution branch from fb34de0 to 7c9454c Compare January 11, 2025 10:18
@mproffitt
Copy link
Author

Leaving in draft until this has been tested fully inside a cluster

In its current form, if `cmd.Run` fails, then the function immediately
exits with no reason given for the termination. This makes debugging
scripts hard to understand as no indication is given for the failure,
other than a failure occured.

By trapping the error returned from `cmd.Run`, we first process the
buffers for both `stdout` and `stderr` and set these to the `dxr`.

Additionally we capture a truncated `stderr` from the command error
which can help point to where the command failed, setting this as the
Fatal error message returned as an event.

Signed-off-by: Martin Proffitt <mproffitt@choclab.net>
@mproffitt mproffitt force-pushed the rework-shell-execution branch from 7c9454c to 4dbbc02 Compare February 5, 2025 06:55
@mproffitt mproffitt marked this pull request as ready for review February 5, 2025 06:56
@stevendborrelli
Copy link
Collaborator

Hello @mproffitt can you indicate what kind of testing you have done in-cluster for this PR?

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

Successfully merging this pull request may close these issues.

2 participants