Full pretty errors in container-path storage check
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 19 Dec 2012 14:14:08 +0000 (16:14 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 19 Dec 2012 14:14:08 +0000 (16:14 +0200)
kamaki/cli/commands/pithos_cli.py
kamaki/cli/errors.py

index 9fb981b..e938d27 100644 (file)
@@ -216,7 +216,8 @@ class _store_container_command(_store_account_command):
     def __init__(self, arguments={}):
         super(_store_container_command, self).__init__(arguments)
         self.arguments['container'] =\
-            ValueArgument('Set container to operate on (not permanent)', '--container')
+            ValueArgument('Set container to work with (temporary)',
+                '--container')
         self.container = None
         self.path = None
 
@@ -228,27 +229,27 @@ class _store_container_command(_store_account_command):
         except AssertionError as err:
             raiseCLIError(err)
 
+        generic_details = ['Choose one of the following options:',
+        '  1. Set store.container variable (permanent)',
+        '     /config set store.container <container>',
+        '  2. --container=<container> (temporary, overrides 1)',
+        '  3. Use <container>:<path> (temporary, overrides all)']
         cont, sep, path = container_with_path.partition(':')
 
         if sep:
             if not cont:
-                raiseCLIError(None, 'Container is missing\n', importance=1,
-                    details=['Choose one of the following options:',
-                    '  1. Set store.container variable (permanent)',
-                    '     /config set store.container <container>',
-                    '  2. --container=<container> (temporary, overrides 1)',
-                    '  3. Use <container>:<path> (temporary, overides all)'])
+                raiseCLIError(CLISyntaxError('Container is missing\n',
+                    details=generic_details))
             alt_cont = self.get_argument('container')
             if alt_cont and cont != alt_cont:
-                raiseCLIError(None,
+                raiseCLIError(CLISyntaxError(
                     'Conflict: 2 containers (%s, %s)' % (cont, alt_cont),
-                    importance=1)
+                    details=generic_details))
             self.container = cont
             if not path:
-                raiseCLIError(None,
+                raiseCLIError(CLISyntaxError(
                     'Path is missing for object in container %s' % cont,
-                    importance=1,
-                    details='Usage: <container>:<object path>')
+                    details=generic_details))
             self.path = path
         else:
             alt_cont = self.get_argument('container') or self.client.container
@@ -261,9 +262,8 @@ class _store_container_command(_store_account_command):
             else:
                 self.container = cont
                 raiseCLIError(CLISyntaxError(
-                    'Syntax error: container and path are both required',
-                    importance=1,
-                    details='Usage: <container>:<object path>'))
+                    'Both container and path are required',
+                    details=generic_details))
 
     def main(self, container_with_path=None, path_is_optional=True):
         super(_store_container_command, self).main()
index a421e10..d1fbe05 100644 (file)
@@ -38,6 +38,7 @@ recvlog = logging.getLogger('clients.recv')
 
 
 class CLIError(Exception):
+
     def __init__(self, message, details=[], importance=0):
         """
         @message is the main message of the Error
@@ -47,7 +48,7 @@ class CLIError(Exception):
         """
         message += '' if message and message[-1] == '\n' else '\n'
         super(CLIError, self).__init__(message)
-        self.details = details if isinstance(details, list)\
+        self.details = list(details) if isinstance(details, list)\
             else [] if details is None else ['%s' % details]
         try:
             self.importance = int(importance)
@@ -92,6 +93,7 @@ def raiseCLIError(err, message='', importance=0, details=[]):
     :raises CLIError: it is the purpose of this method
     """
     from traceback import format_stack
+
     stack = ['%s' % type(err)] if err else ['<kamaki.cli.errors.CLIError>']
     stack += format_stack()
     try:
@@ -101,6 +103,7 @@ def raiseCLIError(err, message='', importance=0, details=[]):
 
     details = ['%s' % details] if not isinstance(details, list)\
         else list(details)
+    details += getattr(err, 'details', [])
 
     if err:
         origerr = '%s' % err
@@ -117,10 +120,6 @@ def raiseCLIError(err, message='', importance=0, details=[]):
 
     if origerr not in details + [message]:
         details.append(origerr)
-    try:
-        details.append(err.details)
-    except AttributeError:
-        pass
 
     message += '' if message and message[-1] == '\n' else '\n'
     if status:
@@ -130,4 +129,5 @@ def raiseCLIError(err, message='', importance=0, details=[]):
         except ValueError:
             raise CLIError(message, details, importance)
         importance = status // 100
+    importance = getattr(err, 'importance', importance)
     raise CLIError(message, details, importance)