Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
errors = []
def err(f):
errors.append(f)
txaio.add_callbacks(f, None, err)
try:
raise exception
except RuntimeError:
txaio.reject(f)
run_once()
assert len(errors) == 1
assert isinstance(errors[0], txaio.IFailedFuture)
assert exception == errors[0].value
tb = txaio.failure_format_traceback(errors[0])
assert 'RuntimeError' in tb
assert 'it failed' in tb
assert txaio.failure_message(errors[0]) == 'RuntimeError: it failed'
assert 'it failed' in str(errors[0])
errors.append(f)
txaio.add_callbacks(f, None, err)
try:
raise exception
except RuntimeError:
fail = txaio.create_failure()
txaio.reject(f, fail)
run_once()
assert len(errors) == 1
assert isinstance(errors[0], txaio.IFailedFuture)
assert exception == errors[0].value
assert txaio.failure_traceback(errors[0]) is not None
tb = txaio.failure_format_traceback(errors[0])
assert 'RuntimeError' in tb
assert 'it failed' in tb
assert txaio.failure_message(errors[0]) == 'RuntimeError: it failed'
assert 'it failed' in str(errors[0])
def component_failure(comp, f):
log.error("Component '{c}' error: {msg}", c=comp, msg=txaio.failure_message(f))
log.debug("Component error: {tb}", tb=txaio.failure_format_traceback(f))
# double-check: is a component-failure still fatal to the
# startup process (because we passed consume_exception=False
# to gather() below?)
return None
def render_POST(self, request):
"""
Request to create a new WAMP session.
"""
self.log.debug("WampLongPoll: creating new session ..")
payload = request.content.read().decode('utf8')
try:
options = json.loads(payload)
except Exception:
f = create_failure()
self.log.error(
"Couldn't parse WAMP request body: {msg}",
msg=failure_message(f),
)
self.log.debug("{msg}", msg=failure_format_traceback(f))
return self._parent._fail_request(request, b"could not parse WAMP session open request body")
if not isinstance(options, dict):
return self._parent._fail_request(request, b"invalid type for WAMP session open request")
if 'protocols' not in options:
return self._parent._fail_request(request, "missing attribute 'protocols' in WAMP session open request")
# determine the protocol to speak
#
protocol = None
serializer = None
for p in options['protocols']:
version, serializerId = parseSubprotocolIdentifier(p)
if version == 2 and serializerId in self._parent._serializers.keys():
serializer = self._parent._serializers[serializerId]
def error(fail):
self.log.info("Internal error {msg}", msg=txaio.failure_message(fail))
self.log.debug("{tb}", tb=txaio.failure_format_traceback(fail))
txaio.reject(done_f, fail)
def on_startup_error(err):
term_print('CROSSBAR:NODE_STARTUP_FAILED')
exit_info['was_clean'] = False
log.error("Could not start node: {tb}", tb=failure_format_traceback(err))
if reactor.running:
reactor.stop()
This is an internal generic error-handler for errors encountered
when calling down to on*() handlers that can reasonably be
expected to be overridden in user code.
Note that it *cancels* the error, so use with care!
Specifically, this should *never* be added to the errback
chain for a Deferred/coroutine that will make it out to user
code.
'''
try:
self.onUserError(fail, msg)
except Exception:
self.log.error(
"Internal error: {tb}",
tb=txaio.failure_format_traceback(txaio.create_failure()),
)
return None
# and what the problem is. See err(3) for more
# information."
for (lib, fn, reason) in e.args[0]:
self.log.error(u"TLS failure: {reason}", reason=reason)
self.log.error(u"Marking this transport as failed")
transport.failed()
else:
f = txaio.create_failure()
self.log.error(
u'Connection failed: {error}',
error=txaio.failure_message(f),
)
# some types of errors should probably have
# stacktraces logged immediately at error
# level, e.g. SyntaxError?
self.log.debug(u'{tb}', tb=txaio.failure_format_traceback(f))
else:
self.log.debug(u"Not reconnecting")
reconnect = False
else:
# check if there is any transport left we can use
# to connect
if not self._can_reconnect():
self.log.info("No remaining transports to try")
reconnect = False
# only actually try to connect using the transport,
# if the transport hasn't reached max. connect count
if transport.can_reconnect():
delay = transport.next_delay()
self.log.debug(
'trying transport {transport_idx} using connect delay {transport_delay}',
transport_idx=transport.idx,
transport_delay=delay,
)
yield sleep(delay)
try:
yield self._connect_once(reactor, transport)
except Exception as e:
f = txaio.create_failure()
self.log.error(u'component failed: {error}', error=txaio.failure_message(f))
self.log.debug(u'{tb}', tb=txaio.failure_format_traceback(f))
# If this is a "fatal error" that will never work,
# we bail out now
if isinstance(e, ApplicationError):
if e.error in [u'wamp.error.no_such_realm']:
reconnect = False
self.log.error(u"Fatal error, not reconnecting")
# The thinking here is that we really do
# want to 'raise' (and thereby fail the
# entire "start" / reconnect loop) because
# if the realm isn't valid, we're "never"
# going to succeed...
raise
self.log.error(u"{msg}", msg=e.error_message())
elif _is_ssl_error(e):
# Quoting pyOpenSSL docs: "Whenever
# [SSL.Error] is raised directly, it has a