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

When a command fails, print its error in multiple lines #178

Merged
merged 2 commits into from
Aug 1, 2023

Conversation

querti
Copy link
Collaborator

@querti querti commented Jul 25, 2023

When skopeo copy fails, the error message cannot be accessed because the log of the command output gets truncated. Since the command generates new line characters, use them to split the output and log each line separately.

Refers to CLOUDDST-19503

@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (196678a) 100.00% compared to head (ca28d7f) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #178   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines         3026      3078   +52     
=========================================
+ Hits          3026      3078   +52     
Files Changed Coverage Δ
pubtools/_quay/command_executor.py 100.00% <100.00%> (ø)

... and 14 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@querti querti marked this pull request as ready for review July 25, 2023 11:26
@querti querti requested review from zxiong and emilyzheng July 25, 2023 11:27
@@ -182,7 +182,9 @@ def _run_cmd(self, cmd, err_msg=None, tolerate_err=False, stdin=None):
out, err = p.communicate(input=stdin)

if p.returncode != 0 and not tolerate_err:
LOG.error("Command {0} failed with {1}".format(cmd, err))
LOG.error("Command {0} failed with the following error:".format(cmd))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, error can already be shown in multiple lines if it includes "\n":

err = "multiline\nerror\nmessage"

2023-08-01 02:01:30 +0000 [ERROR   ] Command skopeo copy --all docker://registry-proxy.engineering.redhat.com/rh-osbs/rhel8-redis-5:rhel-8.6.0-z-containers-candidate-36737-20220620193816 docker://quay.io/redhat-dev2/test----repo1:121 --format v2s2 failed with multiline
error
message

Does error really have "\n"? Seems only stdout has it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, looks like splitting by \n is not the correct solution for local executor. I have instead added textwrap that splits the long message based on length.

LOG.error("Command {0} failed with {1}".format(cmd, err))
LOG.error("Command {0} failed with the following error:".format(cmd))
for line in err.splitlines():
LOG.error(line)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an indentation here? For example " " could be enough to make it more readable in logs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@midnightercz midnightercz self-requested a review August 1, 2023 07:45
@querti querti force-pushed the improve-command-logs branch 2 times, most recently from cfbdd66 to eeaa3c2 Compare August 1, 2023 08:23
When skopeo copy fails, the error message cannot be accessed because
the log of the command output gets truncated. Since the command
generates new line characters, use them to split the output and log each
line separately.
@querti querti merged commit 315b717 into release-engineering:master Aug 1, 2023
8 checks passed
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.

4 participants