def __init__(self, e_type: type, e_value: BaseException, traceback: Optional[TracebackType]) -> None: self.e_type = dill.dumps(e_type) self.e_value = dill.dumps(e_value) self.e_traceback = None if traceback is None else Traceback(traceback) if e_value.__cause__ is None: self.cause = None else: cause = e_value.__cause__ self.cause = self.__class__(type(cause), cause, cause.__traceback__)
class RemoteExceptionWrapper: def __init__(self, e_type, e_value, traceback): self.e_type = dill.dumps(e_type) self.e_value = dill.dumps(e_value) self.e_traceback = Traceback(traceback) def reraise(self): reraise(dill.loads(self.e_type), dill.loads(self.e_value), self.e_traceback.as_traceback())
def suppress_warpper(*args, **kwargs): try: func(*args, **kwargs) except: et, ev, tb = sys.exc_info() if notify is not None: notify(except_type=et, except_value=ev, traceback=tb) if verbose == 1 or isinstance(ev, CriticalException): reraise(et, ev, Traceback(tb).as_traceback())
def set_test_result(self, test_id, result_state, output, when, outcome, exc_type=None, exc_value=None, extracted_traceback=None, last_failed_exempt=None): """ Set test result in internal dictionary. Updates UI. Args: test_id: An unique string test identifier. """ update_listbox = False if test_id not in self.test_data: self.test_data[test_id] = {'id': test_id} update_listbox = True if extracted_traceback: py_traceback = Traceback.from_dict( extracted_traceback).as_traceback() extracted_traceback = traceback.extract_tb(py_traceback) output += ''.join( traceback.format_list(extracted_traceback) + [exc_value]) test_data = self.test_data[test_id] test_data['exc_type'] = exc_type test_data['exc_value'] = exc_value test_data['exc_tb'] = extracted_traceback if when == 'call' and last_failed_exempt is not None: test_data['last_failed_exempt'] = last_failed_exempt # Ignore success, except for the 'call' step # ignore successive failure, take only the first if ((outcome != 'passed' or when == 'call') and not test_data.get('result_state')): test_data['result_state'] = result_state test_data['output'] = output if update_listbox: self.ui.init_test_listbox() else: self.ui.update_test_result(test_data) if when == 'teardown': test_data['runstate'] = None self.ui.update_test_line(test_data)
class ExceptionWrapper: """A picklable wrapper suitable for passing exception tracebacks through instances of ``multiprocessing.Queue``. Args: exception (Exception): The exception to wrap. """ def __init__(self, exception): # coverage: disable self.exception = exception _, _, tb = sys.exc_info() self.tb = Traceback(tb) def reraise(self): """Re-raise the exception.""" raise self.exception.with_traceback(self.tb.as_traceback())
def set_result(uid, obj, progress=0): """Place a Future result into cache.""" if isinstance(obj, tuple) and isinstance(obj[1], Exception): # Wrap the tb so it can be transported and re-raised. et, ev, tb = obj obj = (et, ev, Traceback(tb)) obj = dill.dumps(obj) result = { 'uid': uid, 'obj': obj, 'ts': time.time(), 'progress': progress, } cache = caches[settings.FUTURES_CACHE_BACKEND] cache.set('futures:%s' % uid, result, settings.FUTURES_CACHE_TTL)
def on_next(self, msg: Message): type_ = msg.contents.get('type') # self.logger.debug(' type: %s', type_) if type_ is None: return elif type_ != 'log': return # remove unused 'type' value msg.contents.pop('type') # NOTE: Fixes formatting issue used by logging lib, I.E. msg % args args = msg.contents['args'] if isinstance(args, list): msg.contents['args'] = tuple(args) else: msg.contents['args'] = args exc_info = msg.contents['exc_info'] # deserialize exc_info if exc_info: import traceback # FIXME traceback.print_tb(Traceback.from_dict(exc_info).as_traceback()) return # exc_info = (None, None, Traceback.from_dict(exc_info[2]).as_traceback()) """ new_exc_info = [] # Exception type # FIXME: bad exception handeling try: type_ = globals()['__builtins__'][exc_info[0]] # pass in excption arguments value = type_(*exc_info[1]) traceback = Traceback.from_dict(exc_info[2]).as_traceback() new_exc_info = [type_, value, traceback] msg.contents['exc_info'] = new_exc_info except KeyError: # FIXME pass """ # overwrite the member record = logging.LogRecord(**msg.contents) if self.passthrough: self.root.handle(record) else: if record.levelno >= self.root.level: self.root.handle(record)
def emit(self, record): args = record.args if isinstance(args, tuple): args = [str(x) for x in record.args] elif isinstance(args, dict): args = str(args) # NOTE: Might need more specific handling in the future else: args = str(args) info = { 'name': record.name, 'level': record.levelno, 'pathname': record.pathname, 'lineno': record.lineno, 'msg': record.msg, 'args': args, 'exc_info': record.exc_info, 'func': record.funcName, 'sinfo': record.stack_info, 'type': 'log' } exc_info = info['exc_info'] if exc_info is not None: # FIXME: It's hard to transmit an exception because the Error type # might be defined in a library that is not installed on the # receiving side. Not sure what the best way to do this is. info['exc_info'] = Traceback(exc_info[2]).to_dict() """ new_exc_info = [] first = exc_info[0] if isinstance(first, Exception): try: first = first.__name__ except AttributeError: first = first.__class__.__name__ print(first, dir(first), isinstance(first, Exception)) new_exc_info.append(first) new_exc_info.append([str(x) for x in exc_info[1].args]) new_exc_info.append(Traceback(exc_info[2]).to_dict()) info['exc_info'] = new_exc_info """ self.messaging.send_log(**info)
def detail(worker: "sy.workers.AbstractWorker", error_tuple: Tuple[str, str, dict]): """ Detail and re-raise an Exception forwarded by another worker """ error_name, traceback_str, attributes = error_tuple error_name, traceback_str = error_name.decode("utf-8"), traceback_str.decode("utf-8") attributes = sy.serde._detail(worker, attributes) # De-serialize the traceback tb = Traceback.from_string(traceback_str) # Check that the error belongs to a valid set of Exceptions if error_name in dir(sy.exceptions): error_type = getattr(sy.exceptions, error_name) error = error_type() # Include special attributes if any for attr_name, attr in attributes.items(): setattr(error, attr_name, attr) reraise(error_type, error, tb.as_traceback()) else: raise ValueError(f"Invalid Exception returned:\n{traceback_str}")
def raise_for_status(self, allow_redirects=True): """Raises stored :class:`HTTPError` or :class:`URLError`, if one occurred.""" if self.status_code == 304: return elif self.error: if self.traceback: six.reraise(Exception, Exception(self.error), Traceback.from_string(self.traceback).as_traceback()) http_error = HTTPError(self.error) elif (self.status_code >= 300) and (self.status_code < 400) and not allow_redirects: http_error = HTTPError('%s Redirection' % (self.status_code)) elif (self.status_code >= 400) and (self.status_code < 500): http_error = HTTPError('%s Client Error' % (self.status_code)) elif (self.status_code >= 500) and (self.status_code < 600): http_error = HTTPError('%s Server Error' % (self.status_code)) else: return http_error.response = self raise http_error
class RemoteExceptionWrapper: def __init__(self, e_type, e_value, traceback): self.e_type = dill.dumps(e_type) self.e_value = dill.dumps(e_value) self.e_traceback = Traceback(traceback) def reraise(self): t = dill.loads(self.e_type) # the type is logged here before deserialising v and tb # because occasionally there are problems deserialising the # value (see #785, #548) and the fix is related to the # specific exception type. logger.debug("Reraising exception of type {}".format(t)) v = dill.loads(self.e_value) tb = self.e_traceback.as_traceback() reraise(t, v, tb)
def _unpack_pickled_error(self, pickled_error: bytes) -> Tuple[str, str]: """Unpacks `pickled_error` into an error `message` and `tb` string.""" exc = pickle.loads(pickled_error) message = traceback.format_exception(*exc)[-1] tb = json.dumps(Traceback(exc[2]).to_dict()) return message, tb
def __init__(self, exception): # coverage: disable self.exception = exception _, _, tb = sys.exc_info() self.tb = Traceback(tb)
def __init__(self, e_type, e_value, traceback): self.e_type = dill.dumps(e_type) self.e_value = dill.dumps(e_value) self.e_traceback = Traceback(traceback)
def __init__(self, e_type: type, e_value: Exception, traceback: TracebackType) -> None: self.e_type = dill.dumps(e_type) self.e_value = dill.dumps(e_value) self.e_traceback = Traceback(traceback)
def do_show_last_error(self, *args, **kwargs): exc_info = _sys.exc_info() if exc_info[2] is None: return 'No problems here boss!' self.logger.debug('exc_info: %s', exc_info) return Traceback(exc_info[2]).to_dict()
def run(self): try: self._ret.put(self.try_run()) except BaseException as ex: exc_type, exc_value, exc_traceback = sys.exc_info() self._exc.put((exc_type, exc_value, Traceback(exc_traceback)))