-
Notifications
You must be signed in to change notification settings - Fork 13
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
When a command fails, print its error in multiple lines #178
Conversation
f5706ea
to
2ef2366
Compare
Codecov ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
2ef2366
to
8fd3257
Compare
@@ -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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pubtools/_quay/command_executor.py
Outdated
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
cfbdd66
to
eeaa3c2
Compare
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.
600ec7e
to
e73b43d
Compare
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