cli: add "catch all" for exceptions to sanitize output
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 23 Apr 2016 01:06:14 +0000 (21:06 -0400)
committerAntoine Busque <abusque@efficios.com>
Tue, 26 Apr 2016 17:10:04 +0000 (13:10 -0400)
This prevents the user from seeing Python tracebacks, and in MI
mode, it makes sure that only the error object is printed if there is
an error, wherever this error happens.

Eventually, log statements should be added at strategic locations to
optionally provide more information about a failure to the user (and
to bug reports).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
lttnganalyses/cli/command.py

index 5128d411db6ce015c40106c8366664b0fdd00f14..7c3028bbe0c9e697cadea0fa0925aa8159767fad 100644 (file)
@@ -55,25 +55,31 @@ class Command:
         self._traces = None
         self._ticks = 0
         self._mi_mode = mi_mode
-        self._create_automaton()
-        self._mi_setup()
+        self._run_step('create automaton', self._create_automaton)
+        self._run_step('setup MI', self._mi_setup)
 
     @property
     def mi_mode(self):
         return self._mi_mode
 
-    def run(self):
+    def _run_step(self, action_title, fn):
         try:
-            self._parse_args()
-            self._open_trace()
-            self._create_analysis()
-
-            if self._mi_mode and not self._args.test_compatibility:
-                self._run_analysis()
-
-            self._close_trace()
+            fn()
         except KeyboardInterrupt:
+            self._print('Cancelled by user')
             sys.exit(0)
+        except Exception as e:
+            self._gen_error('Cannot {}: {}'.format(action_title, e))
+
+    def run(self):
+        self._run_step('parse arguments', self._parse_args)
+        self._run_step('open trace', self._open_trace)
+        self._run_step('create analysis', self._create_analysis)
+
+        if self._mi_mode and not self._args.test_compatibility:
+            self._run_step('run analysis', self._run_analysis)
+
+        self._run_step('close trace', self._close_trace)
 
     def _mi_error(self, msg, code=None):
         print(json.dumps(mi.get_error(msg, code)))
This page took 0.024507 seconds and 5 git commands to generate.