diff --git a/knack/cli.py b/knack/cli.py index f6c33b5..f46ee0d 100644 --- a/knack/cli.py +++ b/knack/cli.py @@ -157,8 +157,11 @@ def raise_event(self, event_name, **kwargs): func(self, **kwargs) def exception_handler(self, ex): # pylint: disable=no-self-use - """ The default exception handler for unknown CLI exceptions. """ - logger.exception(ex) + """ The default exception handler """ + if isinstance(ex, CLIError): + logger.error(ex) + else: + logger.exception(ex) return 1 def invoke(self, args, initial_invocation_data=None, out_file=None): @@ -198,9 +201,6 @@ def invoke(self, args, initial_invocation_data=None, out_file=None): self.output.out(cmd_result, formatter=formatter, out_file=out_file) self.raise_event(EVENT_CLI_POST_EXECUTE) exit_code = 0 - except CLIError as ex: - logger.error(ex) - exit_code = 1 except KeyboardInterrupt: exit_code = 1 except Exception as ex: # pylint: disable=broad-except