replace log_support.failure calls
This commit is contained in:
parent
4ca33505b5
commit
fa8190356a
5 changed files with 39 additions and 39 deletions
|
@ -602,14 +602,14 @@ class Daemon(AuthJSONRPCServer):
|
|||
d = defer.succeed(None)
|
||||
|
||||
d.addCallback(lambda _: self._stop_server())
|
||||
d.addErrback(log_support.failure, log, 'Failure while shutting down: %s')
|
||||
d.addErrback(log.fail(), 'Failure while shutting down')
|
||||
d.addCallback(lambda _: self._stop_reflector())
|
||||
d.addErrback(log_support.failure, log, 'Failure while shutting down: %s')
|
||||
d.addErrback(log.fail(), 'Failure while shutting down')
|
||||
d.addCallback(lambda _: self._stop_file_manager())
|
||||
d.addErrback(log_support.failure, log, 'Failure while shutting down: %s')
|
||||
d.addErrback(log.fail(), 'Failure while shutting down')
|
||||
if self.session is not None:
|
||||
d.addCallback(lambda _: self.session.shut_down())
|
||||
d.addErrback(log_support.failure, log, 'Failure while shutting down: %s')
|
||||
d.addErrback(log.fail(), 'Failure while shutting down')
|
||||
return d
|
||||
|
||||
def _update_settings(self, settings):
|
||||
|
@ -1468,9 +1468,20 @@ class Daemon(AuthJSONRPCServer):
|
|||
return self._render_response(None, BAD_REQUEST)
|
||||
|
||||
d = self._resolve_name(name, force_refresh=force)
|
||||
# TODO: this is the rpc call that returns a server.failure.
|
||||
# what is up with that?
|
||||
d.addCallbacks(
|
||||
lambda info: self._render_response(info, OK_CODE),
|
||||
errback=handle_failure, errbackArgs=('Failed to resolve name: %s',)
|
||||
# TODO: Is server.failure a module? It looks like it:
|
||||
#
|
||||
# In [1]: import twisted.web.server
|
||||
# In [2]: twisted.web.server.failure
|
||||
# Out[2]: <module 'twisted.python.failure' from
|
||||
# '.../site-packages/twisted/python/failure.pyc'>
|
||||
#
|
||||
# If so, maybe we should return something else.
|
||||
errback=log.fail(lambda: server.failure),
|
||||
errbackArgs=('Failed to resolve name: %s',)
|
||||
)
|
||||
return d
|
||||
|
||||
|
@ -2692,18 +2703,6 @@ def get_lbry_file_search_value(p):
|
|||
raise NoValidSearch()
|
||||
|
||||
|
||||
def handle_failure(err, msg):
|
||||
log_support.failure(err, log, msg)
|
||||
# TODO: Is this a module? It looks like it:
|
||||
#
|
||||
# In [1]: import twisted.web.server
|
||||
# In [2]: twisted.web.server.failure
|
||||
# Out[2]: <module 'twisted.python.failure' from '.../site-packages/twisted/python/failure.pyc'>
|
||||
#
|
||||
# If so, maybe we should return something else.
|
||||
return server.failure
|
||||
|
||||
|
||||
def run_reflector_factory(factory):
|
||||
reflector_server = random.choice(conf.settings.reflector_servers)
|
||||
reflector_address, reflector_port = reflector_server
|
||||
|
|
|
@ -117,9 +117,8 @@ def update_settings_from_args(args):
|
|||
settings.update(to_pass)
|
||||
|
||||
|
||||
def log_and_kill(failure, analytics_manager):
|
||||
def kill(failure, analytics_manager):
|
||||
analytics_manager.send_server_startup_error(failure.getErrorMessage() + " " + str(failure))
|
||||
log_support.failure(failure, log, 'Failed to startup: %s')
|
||||
reactor.callFromThread(reactor.stop)
|
||||
|
||||
|
||||
|
@ -130,14 +129,13 @@ def start_server_and_listen(launchui, use_auth, analytics_manager):
|
|||
launchui: set to true to open a browser window
|
||||
use_auth: set to true to enable http authentication
|
||||
analytics_manager: to send analytics
|
||||
kwargs: passed along to `DaemonServer().start()`
|
||||
"""
|
||||
daemon_server = DaemonServer(analytics_manager)
|
||||
d = daemon_server.start(use_auth)
|
||||
if launchui:
|
||||
d.addCallback(lambda _: webbrowser.open(settings.UI_ADDRESS))
|
||||
d.addCallback(lambda _: analytics_manager.send_server_startup_success())
|
||||
d.addErrback(log_and_kill, analytics_manager)
|
||||
d.addErrback(log.fail(kill, analytics_manager), 'Failed to startup')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -5,7 +5,6 @@ import random
|
|||
|
||||
from twisted.internet import threads, defer, reactor
|
||||
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
|
||||
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
|
||||
from lbrynet.metadata.Metadata import Metadata
|
||||
|
@ -68,7 +67,12 @@ class Publisher(object):
|
|||
d.addCallback(lambda _: self._claim_name())
|
||||
d.addCallback(lambda _: self.set_status())
|
||||
d.addCallback(lambda _: self.start_reflector())
|
||||
d.addCallbacks(lambda _: _show_result(), self._show_publish_error)
|
||||
d.addCallbacks(
|
||||
lambda _: _show_result(),
|
||||
errback=log.fail(self._throw_publish_error),
|
||||
errbackArgs=(
|
||||
"An error occurred publishing %s to %s", self.file_name, self.publish_name)
|
||||
)
|
||||
return d
|
||||
|
||||
def start_reflector(self):
|
||||
|
@ -151,11 +155,13 @@ class Publisher(object):
|
|||
self.metadata['content_type'] = get_content_type(filename)
|
||||
self.metadata['ver'] = Metadata.current_version
|
||||
|
||||
def _show_publish_error(self, err):
|
||||
log_support.failure(
|
||||
err, log, "An error occurred publishing %s to %s. Error: %s.",
|
||||
self.file_name, self.publish_name)
|
||||
return defer.fail(Exception("Publish failed"))
|
||||
def _throw_publish_error(self, err):
|
||||
# TODO: I'm not a fan of the log and re-throw, especially when
|
||||
# the new exception is more generic. Look over this to
|
||||
# see if there is a reason not to remove the errback
|
||||
# handler and allow the original exception to move up
|
||||
# the stack.
|
||||
raise Exception("Publish failed")
|
||||
|
||||
|
||||
def get_content_type(filename):
|
||||
|
|
|
@ -10,7 +10,6 @@ from twisted.python.failure import Failure
|
|||
from txjsonrpc import jsonrpclib
|
||||
from lbrynet.core.Error import InvalidAuthenticationToken, InvalidHeaderError, SubhandlerError
|
||||
from lbrynet.conf import settings
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.lbrynet_daemon.auth.util import APIKey, get_auth_message
|
||||
from lbrynet.lbrynet_daemon.auth.client import LBRY_SECRET
|
||||
|
||||
|
@ -117,11 +116,6 @@ class AuthJSONRPCServer(AuthorizedBase):
|
|||
request.write(fault)
|
||||
request.finish()
|
||||
|
||||
def _log_and_render_error(self, failure, request, message=None, **kwargs):
|
||||
msg = message or "API Failure: %s"
|
||||
log_support.failure(Failure(failure), log, msg)
|
||||
self._render_error(failure, request, **kwargs)
|
||||
|
||||
def render(self, request):
|
||||
notify_finish = request.notifyFinish()
|
||||
assert self._check_headers(request), InvalidHeaderError
|
||||
|
@ -192,7 +186,10 @@ class AuthJSONRPCServer(AuthorizedBase):
|
|||
# cancel the response if the connection is broken
|
||||
notify_finish.addErrback(self._response_failed, d)
|
||||
d.addCallback(self._callback_render, request, version, reply_with_next_secret)
|
||||
d.addErrback(self._log_and_render_error, request, version=version)
|
||||
d.addErrback(
|
||||
log.fail(self._render_error, request, version=version),
|
||||
'Failed to process %s', function_name
|
||||
)
|
||||
return server.NOT_DONE_YET
|
||||
|
||||
def _register_user_session(self, session_id):
|
||||
|
|
|
@ -5,7 +5,6 @@ from twisted.protocols.basic import FileSender
|
|||
from twisted.internet.protocol import Protocol, ClientFactory
|
||||
from twisted.internet import defer, error
|
||||
|
||||
from lbrynet.core import log_support
|
||||
from lbrynet.reflector.common import IncompleteResponse
|
||||
|
||||
|
||||
|
@ -153,8 +152,7 @@ class BlobReflectorClient(Protocol):
|
|||
'blob_size': self.next_blob_to_send.length
|
||||
}))
|
||||
|
||||
def log_fail_and_disconnect(self, err, blob_hash):
|
||||
log_support.failure(err, log, "Error reflecting blob %s: %s", blob_hash)
|
||||
def disconnect(self, err):
|
||||
self.transport.loseConnection()
|
||||
|
||||
def send_next_request(self):
|
||||
|
@ -172,7 +170,9 @@ class BlobReflectorClient(Protocol):
|
|||
# send the server the next blob hash + length
|
||||
d.addCallbacks(
|
||||
lambda _: self.send_blob_info(),
|
||||
lambda err: self.log_fail_and_disconnect(err, blob_hash))
|
||||
errback=log.fail(self.disconnect),
|
||||
errbackArgs=("Error reflecting blob %s", blob_hash)
|
||||
)
|
||||
return d
|
||||
else:
|
||||
# close connection
|
||||
|
|
Loading…
Reference in a new issue