-
Notifications
You must be signed in to change notification settings - Fork 290
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
exceptions: change error message for CommandFailedError #1652
base: main
Are you sure you want to change the base?
Conversation
b6f00af
to
0d667e8
Compare
@@ -51,7 +51,12 @@ class CommandFailedError(Exception): | |||
Exception thrown on command failure | |||
""" | |||
def __init__(self, command, exitstatus, node=None, label=None): | |||
self.command = command |
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.
From one side this might seem useful for a user to copy and paste command,
but from another point of view, it is bad for debugging, it will be not possible to figure out what
exactly command was before it got to the Exception. Also, the next line joining command with spaces is absolutely not the same as it makes it quoted inside run methods, which makes it hard to reproduce issue.
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.
From one side this might seem useful for a user to copy and paste command,
but from another point of view, it is bad for debugging, it will be not possible to figure out what
exactly command was before it got to the Exception.
I don't see how would figuring out become difficult since parameter would be printed as it is (at least individually). For example, ['ls', 'dir1']
would become ls dir1
. I have grepped plenty times and either don't make much of a difference.
Also, the next line joining command with spaces is absolutely not the same as it makes it quoted inside run methods, which makes it hard to reproduce issue.
Same as what?
Umm... are you referring to this line when you say "quoted inside run methods"? I think there's no nice way around that but printing as string definitely takes away effort of deleting a dozen inverted commas every time.
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.
Yes, I mean the quotation thing.
Also, if you want to get the exact command, it is already printed in the logs, you just need to find the place where debug is printing the command out before the execution.
0d667e8
to
831dc66
Compare
teuthology/exceptions.py
Outdated
@@ -51,7 +51,12 @@ class CommandFailedError(Exception): | |||
Exception thrown on command failure | |||
""" | |||
def __init__(self, command, exitstatus, node=None, label=None): | |||
self.command = command | |||
if isinstance(command, (list, tuple)): | |||
self.command = ' '.join(command) |
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.
I think the right place for this transformation would be in the __str__
method. It would improve readability, yes.
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.
True, that'll be much better. Updated the patch now. Thanks!
831dc66
to
9013aa6
Compare
9013aa6
to
b35aa79
Compare
def __init__(self, cmd, exitstatus, node=None, label=None): | ||
self.cmd = 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.
Why renaming command
to cmd
?
- This change is not necessary.
- Breaks the convention of naming arguments.
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.
Why renaming command to cmd?
Lesser effort to type, and easier to keep statements under 79 characters which in turn saves us from hard to read split-over-several-line statements .
teuthology/exceptions.py
Outdated
if isinstance(self.cmd, (list, tuple)): | ||
self.cmd = [str(Raw) if isinstance(x, Raw) else x \ | ||
for x in self.cmd] | ||
self.cmd = ' '.join(self.cmd) | ||
elif isinstance(self.cmd, str): | ||
self.cmd = sub(r'Raw\([\'"](.*)[\'"]\)', r'\1', self.cmd) | ||
else: | ||
raise RuntimeError('variable "command" is not str, list or tuple') | ||
|
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.
Do not override the original command, just return the str representation computed in local variable.
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.
Okay. That would be better, I guess. Thanks!
teuthology/orchestra/run.py
Outdated
import logging | ||
import shutil | ||
|
||
from teuthology.contextutil import safe_while | ||
from teuthology.exceptions import (CommandCrashedError, CommandFailedError, | ||
ConnectionLostError) | ||
from teuthology.orchestra.run_helper import Raw, quote |
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.
Instead of run_helper
I suggest more appropriate name for the module, util
or tool
or common
or for example
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.
I find run_helper appropriate since it contains classes that help run.py.
BTW I moving rest of misc. classes from run.py to run_helper.py too.
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.
that looks weird, if you really want to have run based classes it would have more appropriate to have this layout:
teuthology/orchestra/run/__init__.py
teuthology/orchestra/run/helper.py
instead of underscore separated.
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.
I personally feel this a bit of overkill but I don't really mind.
@batrick Any opinion?
teuthology/exceptions.py
Outdated
for x in self.cmd] | ||
self.cmd = ' '.join(self.cmd) | ||
elif isinstance(self.cmd, str): | ||
self.cmd = sub(r'Raw\([\'"](.*)[\'"]\)', r'\1', self.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.
Why this branch is needed?
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.
Transforms str 'param1 param2 Raw('&&") param3'
to str 'param1 param2 && param3'
.
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.
why this is needed to transform I do not understand
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.
or in which situation this is happening...
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.
Same reason for which i am converting list
to str
.
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.
well... I don't understand why we do not use quote method here from the helper?
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.
How would that do the job?
$ python
Python 3.8.9 (default, Apr 6 2021, 00:00:00)
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from teuthology.orchestra.run_helper import Raw, quote
>>> a = quote('a b Raw("&&") c')
>>> a
'a b Raw("&&") c'
>>>
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.
Yep, but how is it possible to have the Raw in the string? From my point of view if you have Raw in the str it means that you've made a typo and this command is not going to be run successfully.
No call there too.
I will get rid of it. |
b35aa79
to
1cc8aa2
Compare
Class Raw has been moved from teuthology.orchestra.run to teuthology.orchestra.run_helper. Update Ceph QA code accordingly. Related PR: ceph/teuthology#1652. Signed-off-by: Rishabh Dave <[email protected]>
Class Raw is needed in teuthology.exceptions and importing it from teuthology.orchestra.run is not possible since it would lead to a circular dependecy. Move these classes to a new module, run_helper.py, to avoid this and import through run_helper.py instead. Signed-off-by: Rishabh Dave <[email protected]>
For the convenience of user, print the command that led to CommandFailedError in error message as a str than as a list or a tuple. This makes it more readable and enables the user to copy and use the command without any hassles. This commit also uses the opportunity to rename the variable "command" to "cmd" and "self.command" to "self.cmd" in CommandFailedError for convenience and so that it's easy to keep statements under 80 characters. Signed-off-by: Rishabh Dave <[email protected]>
Since the function is dead code, there are no calls to it in teuthology or ceph repository, remove it. Signed-off-by: Rishabh Dave <[email protected]>
1cc8aa2
to
c013aa4
Compare
Class Raw has been moved from teuthology.orchestra.run to teuthology.orchestra.run_helper. Update Ceph QA code accordingly. Related PR: ceph/teuthology#1652. Signed-off-by: Rishabh Dave <[email protected]>
Class Raw has been moved from teuthology.orchestra.run to teuthology.orchestra.run_helper. Update Ceph QA code accordingly. Related PR: ceph/teuthology#1652. Signed-off-by: Rishabh Dave <[email protected]>
Class Raw has been moved from teuthology.orchestra.run to teuthology.orchestra.run_helper. Update Ceph QA code accordingly. Related PR: ceph/teuthology#1652. Signed-off-by: Rishabh Dave <[email protected]>
Class Raw has been moved from teuthology.orchestra.run to teuthology.orchestra.run_helper. Update Ceph QA code accordingly. Related PR: ceph/teuthology#1652. Signed-off-by: Rishabh Dave <[email protected]>
Class Raw has been moved from teuthology.orchestra.run to teuthology.orchestra.run_helper. Update Ceph QA code accordingly. Related PR: ceph/teuthology#1652. Signed-off-by: Rishabh Dave <[email protected]>
Class Raw has been moved from teuthology.orchestra.run to teuthology.orchestra.run_helper. Update Ceph QA code accordingly. Related PR: ceph/teuthology#1652. Signed-off-by: Rishabh Dave <[email protected]>
For the convenience of user, print the command that led to
CommandFailedError in error message as a str than as a list or a tuple.
This makes it more readable and enables the user to copy and use the
command without any hassles.