fix: log stderr as well#8
Conversation
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the Cloud Custodian execution flow to include captured stderr output in the structured error list when command execution fails, improving error visibility during failures.
Changes:
- Append
result.Stderrtoresult.Errorswhencmd.Run()returns an error.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err != nil { | ||
| result.Err = fmt.Errorf("custodian execution failed: %w", err) | ||
| result.Errors = append(result.Errors, result.Err.Error()) | ||
| if result.Stderr != "" { | ||
| result.Errors = append(result.Errors, result.Stderr) | ||
| } |
There was a problem hiding this comment.
This introduces new behavior (stderr is added to result.Errors when cmd.Run() fails), but there is no test exercising the failure path with non-empty stderr to ensure it’s included (and to lock in expectations around formatting/truncation). Please add a unit test in the existing TestCommandCustodianExecutor suite for a script that exits non-zero and writes to stderr.
| if result.Stderr != "" { | ||
| result.Errors = append(result.Errors, result.Stderr) | ||
| } |
There was a problem hiding this comment.
Appending raw result.Stderr into result.Errors will duplicate stderr in the final payload (Execution.Stderr is already populated) and will also cause the warning log at the end of Execute to emit the full stderr content under the errors field. This can significantly bloat logs/payloads and may include newlines or sensitive data. Consider keeping Errors for discrete error messages and instead logging stderr separately (ideally trimmed and length-capped), or only adding a summarized/truncated stderr entry to Errors.
No description provided.