From 5bc26da4132d4094f39fc853bc8e150394a837ad Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 22 Apr 2016 21:06:14 -0400 Subject: [PATCH 1/1] cli: add "catch all" for exceptions to sanitize output 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 --- lttnganalyses/cli/command.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lttnganalyses/cli/command.py b/lttnganalyses/cli/command.py index 5128d41..7c3028b 100644 --- a/lttnganalyses/cli/command.py +++ b/lttnganalyses/cli/command.py @@ -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))) -- 2.34.1