def errback(failure): try: failure.raiseException() # Should never happen, but just in case raise Exception("errback called without error") except: f.set_exc_info(sys.exc_info())
def errback(failure: failure.Failure) -> None: try: failure.raiseException() # Should never happen, but just in case raise Exception("errback called without error") except: future_set_exc_info(f, sys.exc_info())
def block_on(deferred): cur = [getcurrent()] synchronous = [] def cb(value): if cur: if getcurrent() is cur[0]: synchronous.append((value, None)) else: cur[0].switch(value) return value def eb(failure): if cur: if getcurrent() is cur[0]: synchronous.append((None, failure)) else: failure.throwExceptionIntoGenerator(cur[0]) deferred.addCallbacks(cb, eb) if synchronous: result, failure = synchronous[0] if failure is not None: failure.raiseException() return result try: return get_hub().switch() finally: del cur[0]
def _errback(self, failure): logger.debug2("{0}._errback", self.__class__.__name__) self._freeSession(failure) result = self._renderError(failure) result = self._setCookie(result) result.code = responsecode.INTERNAL_SERVER_ERROR try: failure.raiseException() except OpsiAuthenticationError as error: logger.logException(error) result.code = responsecode.UNAUTHORIZED result.headers.setHeader('www-authenticate', [('basic', { 'realm': self.authRealm })]) except OpsiBadRpcError as error: logger.logException(error) result.code = responsecode.BAD_REQUEST except Exception as error: logger.logException(error, LOG_ERROR) logger.error(failure) return result
def _error_handler(self, failure): if failure.check(tw_error.ConnectionRefusedError): self._on_disconnected() self.reconnect() raise NotConnectedError("Database connection refused.") elif (failure.check(httpclient.RequestError) and failure.value.cause and isinstance(failure.value.cause, tw_error.ConnectionDone)): self._on_disconnected() self.reconnect() raise NotConnectedError("Connection to the database was lost.") else: failure.raiseException()
def _renderError(self, failure): result = http.Response() result.headers.setHeader( 'content-type', http_headers.MimeType("text", "html", {"charset": "utf-8"})) error = u'Unknown error' try: failure.raiseException() except Exception as err: error = {'class': err.__class__.__name__, 'message': unicode(err)} error = toJson({"id": None, "result": None, "error": error}) result.stream = stream.IByteStream(error.encode('utf-8')) return result
def _renderError(self, failure): result = http.Response() result.headers.setHeader( 'content-type', http_headers.MimeType("text", "html", {"charset": "utf-8"})) error = u'Unknown error' try: failure.raiseException() except Exception as error: error = forceUnicode(error) result.stream = stream.IByteStream( stream.IByteStream(error.encode('utf-8'))) return result
def render_eb(self, failure, request, t=0, **_): # This method accepts either a regular Exception or Twisted Failure print failure e, data = '', '' headers = {} # Raise the exception try: if isinstance(failure, twisted.python.failure.Failure): failure.raiseException() else: raise failure # Closed connection error. Nothing to write, and no connection to close. except (twisted.internet.defer.CancelledError), e: return
def _error_handler(self, failure): exception = failure.value msg = failure.getErrorMessage() if isinstance(exception, web_error.Error): status = int(exception.status) if status == 409: raise ConflictError(msg) elif status == 404: raise NotFoundError(msg) else: self.info(exception.response) raise NotImplementedError("Behaviour for response code %d not define yet, FIXME!" % status) elif failure.check(error.ConnectionRefusedError): self._on_disconnected() self.reconnect() raise NotConnectedError("Database connection refused.") else: failure.raiseException()
def _error_handler(self, failure, tag=None): exception = failure.value msg = failure.getErrorMessage() if isinstance(exception, web_error.Error): prefix = (tag + " ") if tag is not None else "" status = int(exception.status) if status == 409: raise ConflictError("%s%s" % (prefix, msg)) elif status == 404: raise NotFoundError("%s%s" % (prefix, msg)) else: self.error('%s%s' % (prefix, exception.response)) raise NotImplementedError( 'Behaviour for response code %d not defined yet, FIXME!' % status) elif failure.check(error.ConnectionRefusedError): self._on_disconnected() self.reconnect() raise NotConnectedError("Database connection refused.") else: failure.raiseException()
def handle_various_errors(failure, vin_or_report, _id): # Do I actually need vin_or_report? if failure.check(NoBalanceError): balance_ok = False print "No balance remaining: no more VINs will be run." error_items['not_attempted'].append(_id) elif failure.check(InvalidVINError): print _id + " is an invalid " + vin_or_report error_items['invalid_vin'].append(_id) elif failure.check(FailNMVTISError): print _id + " was not run, NMVTIS was not available." error_items['fail_nmvtis'].append(_id) elif failure.check(NoRecordsError): print _id + " did not exist in the NMVTIS database." error_items['no_record'].append(_id) else: failure.raiseException()
def handle_error(self, failure): self.mind.svc_message('Uncaught error ' + str(failure.value)) failure.raiseException()