Michael Pasternak has uploaded a new change for review. Change subject: cli: normalize sdk errors ......................................................................
cli: normalize sdk errors Change-Id: Ia4fef4767f7c007ae882c3734b592ab63b32deb5 Signed-off-by: Michael pasternak <mpast...@redhat.com> --- M src/cli/context.py 1 file changed, 17 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/99/14299/1 diff --git a/src/cli/context.py b/src/cli/context.py index e97cf2b..1ab9695 100644 --- a/src/cli/context.py +++ b/src/cli/context.py @@ -37,6 +37,7 @@ from ovirtsdk.infrastructure.errors import \ RequestError, ConnectionError, AmbiguousQueryError +import re class ExecutionContext(object): """A CLI execution context.""" @@ -196,9 +197,19 @@ def __error_to_string(self, err): """Converts an exception to string and normalizing it.""" - if err: - return str(err).replace("[ERROR]::", "") - return err + err_patterns = [ + "[ERROR]::", + "oVirt API connection failure, " + ] + + err_str = str(err) + for err_pattern in err_patterns: + if err_str.find(err_pattern) <> -1: + err_str = err_str.replace( + err_pattern, "" + ) + + return err_str def _handle_exception(self, e): """Handle an exception. Can be overruled in a subclass.""" @@ -213,13 +224,12 @@ sys.stderr.write('%s\n' % e.help) elif isinstance(e, SyntaxError): self.status = getattr(e, 'status', self.SYNTAX_ERROR) - sys.stderr.write('\nerror: %s\n\n' % str(e)) + sys.stderr.write('\nerror: %s\n\n' % self.__error_to_string(e)) if hasattr(e, 'help'): sys.stderr.write('%s\n' % e.help) elif isinstance(e, ConnectionError): self.status = getattr(e, 'status', self.COMMUNICATION_ERROR) - sys.stderr.write('\nerror: %s\n\n' % str(e)\ - .replace("[ERROR]::oVirt API connection failure, ", "")) + sys.stderr.write('\nerror: %s\n\n' % self.__error_to_string(e)) if hasattr(e, 'help'): sys.stderr.write('%s\n' % e.help) else: @@ -227,7 +237,7 @@ if self.settings['cli:debug']: sys.stderr.write(traceback.format_exc()) else: - sys.stderr.write('\nunknown error: %s\n\n' % str(e)) + sys.stderr.write('\nunknown error: %s\n\n' % self.__error_to_string(e)) def _read_command(self): """Parse input until we can parse at least one full command, and -- To view, visit http://gerrit.ovirt.org/14299 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia4fef4767f7c007ae882c3734b592ab63b32deb5 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <mpast...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches