cli: add "catch all" for exceptions to sanitize output
[deliverable/lttng-analyses.git] / 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.023939 seconds and 5 git commands to generate.