def handle_exception(self, exc): log_level = { 'info': logging.DEBUG, 'http': logging.DEBUG, 'default': logging.DEBUG } if not self.exit_code: # only fist exception goes to the screen log_level['info'] = logging.WARNING log_level['http'] = logging.ERROR log_level['default'] = logging.ERROR if isinstance(exc, RCProvider): self.exit_code = exc.get_rc() else: self.exit_code = 1 if isinstance(exc, KeyboardInterrupt): self.__handle_keyboard_interrupt(exc, log_level) log_level['default'] = logging.DEBUG elif isinstance(exc, TaurusException): self.__handle_taurus_exception(exc, log_level['default']) log_level['default'] = logging.DEBUG elif isinstance(exc, HTTPError): msg = "Response from %s: [%s] %s %s" % (exc.geturl(), exc.code, exc.reason, exc.read()) self.log.log(log_level['http'], msg) log_level['default'] = logging.DEBUG self.log.log(log_level['default'], "%s: %s\n%s", type(exc).__name__, exc, get_stacktrace(exc))
def __handle_keyboard_interrupt(self, exc, log_level): if isinstance(exc, ManualShutdown): self.log.log(log_level['info'], "Interrupted by user") elif isinstance(exc, AutomatedShutdown): self.log.log(log_level['info'], "Automated shutdown") elif isinstance(exc, NormalShutdown): self.log.log(logging.DEBUG, "Shutting down by request from code: %s", get_stacktrace(exc)) elif isinstance(exc, KeyboardInterrupt): self.log.log(log_level['info'], "Keyboard interrupt") self.log.debug('Unexpected KeyboardInterrupt at\n%s', get_stacktrace(exc)) else: msg = "Non-KeyboardInterrupt exception %s: %s\n%s" raise ValueError(msg % (type(exc), exc, get_stacktrace(exc)))
def handle_exception(self, exc): info_level = http_level = default_level = logging.DEBUG if not self.exit_code: # only fist exception goes to the screen info_level = logging.WARNING http_level = logging.ERROR default_level = logging.ERROR if isinstance(exc, RCProvider): self.exit_code = exc.get_rc() else: self.exit_code = 1 if isinstance(exc, ManualShutdown): self.log.log(info_level, "Interrupted by user") elif isinstance(exc, AutomatedShutdown): self.log.log(info_level, "Automated shutdown") elif isinstance(exc, NormalShutdown): self.log.log(info_level, "Normal shutdown") elif isinstance(exc, HTTPError): msg = "Response from %s: [%s] %s" % (exc.geturl(), exc.code, exc.reason) self.log.log(http_level, msg) elif isinstance(exc, TaurusException): self.__handle_taurus_exception(exc, default_level) else: self.log.log(default_level, "%s: %s", type(exc).__name__, exc) self.log.log(default_level, get_stacktrace(exc))
def __handle_keyboard_interrupt(self, exc, log_level): if isinstance(exc, ManualShutdown): self.log.log(log_level['info'], "Interrupted by user") elif isinstance(exc, AutomatedShutdown): self.log.log(log_level['info'], "Automated shutdown") elif isinstance(exc, NormalShutdown): self.log.log(logging.DEBUG, "Shutting down by request from code") elif isinstance(exc, KeyboardInterrupt): self.log.log(log_level['info'], "Keyboard interrupt") else: msg = "Non-KeyboardInterrupt exception %s: %s\n%s" raise ValueError(msg % (type(exc), exc, get_stacktrace(exc)))
def __handle_taurus_exception(self, exc, log_level): if isinstance(exc, TaurusConfigError): self.log.log(log_level, "Config Error: %s", exc) elif isinstance(exc, TaurusInternalException): self.log.log(log_level, "Internal Error: %s", exc) elif isinstance(exc, ToolError): self.log.log(log_level, "Child Process Error: %s", exc) elif isinstance(exc, TaurusNetworkError): self.log.log(log_level, "Network Error: %s", exc) else: msg = "Unknown Taurus exception %s: %s\n%s" raise ValueError(msg % (type(exc), exc, get_stacktrace(exc)))
def prepare(self): modules = self.engine.config.get("modules") failure = None for mod_name in modules.keys(): try: self._check_module(mod_name) except BaseException as exc: self.log.error("Failed to instantiate module %s", mod_name) self.log.debug("%s", get_stacktrace(exc)) failure = exc if not failure else failure if failure: raise ToolError("There were errors while checking for installed tools, see messages above") raise NormalShutdown("Done checking for tools installed, will exit now")
def prepare(self): modules = self.engine.config.get("modules") problems = [] for mod_name in modules: try: self._check_module(mod_name) except KeyboardInterrupt: raise # let the engine handle it except BaseException as exc: self.log.error("Failed to instantiate module %s", mod_name) self.log.debug("%s", get_stacktrace(exc)) problems.append(mod_name) if problems: raise ToolError("There were errors while checking for installed tools for %s, see details above" % problems) raise NormalShutdown("Done checking for tools installed, will exit now")
def prepare(self): modules = self.engine.config.get("modules") problems = [] for mod_name in modules.keys(): try: self._check_module(mod_name) except KeyboardInterrupt: raise # let the engine handle it except BaseException as exc: self.log.error("Failed to instantiate module %s", mod_name) self.log.debug("%s", get_stacktrace(exc)) problems.append(mod_name) if problems: raise ToolError("There were errors while checking for installed tools for %s, see details above" % problems) raise NormalShutdown("Done checking for tools installed, will exit now")
def handle_exception(self, exc): log_level = {'info': logging.DEBUG, 'http': logging.DEBUG, 'default': logging.DEBUG} if not self.exit_code: # only fist exception goes to the screen log_level['info'] = logging.WARNING log_level['http'] = logging.ERROR log_level['default'] = logging.ERROR if isinstance(exc, RCProvider): self.exit_code = exc.get_rc() else: self.exit_code = 1 if isinstance(exc, KeyboardInterrupt): self.__handle_keyboard_interrupt(exc, log_level) log_level['default'] = logging.DEBUG elif isinstance(exc, TaurusException): self.__handle_taurus_exception(exc, log_level['default']) log_level['default'] = logging.DEBUG elif isinstance(exc, HTTPError): msg = "Response from %s: [%s] %s %s" % (exc.geturl(), exc.code, exc.reason, exc.read()) self.log.log(log_level['http'], msg) log_level['default'] = logging.DEBUG self.log.log(log_level['default'], "%s: %s\n%s", type(exc).__name__, exc, get_stacktrace(exc))
def prepare(self): modules = self.engine.config.get("modules") problems = [] include_set = self._parse_module_filter(self.settings.get("include", [])) exclude_set = self._parse_module_filter(self.settings.get("exclude", [])) for mod_name in modules: if include_set and mod_name not in include_set: continue if exclude_set and mod_name in exclude_set: continue try: self._check_module(mod_name) except KeyboardInterrupt: raise # let the engine handle it except BaseException as exc: self.log.error("Failed to instantiate module %s", mod_name) self.log.debug("%s", get_stacktrace(exc)) problems.append(mod_name) if problems: raise ToolError("There were errors while checking for installed tools for %s, see details above" % problems) raise NormalShutdown("Done checking for tools installed, will exit now")