Fix how some errors are presented to the user

If an invalid stream descriptor hash is entered, abort and
give a useful error.

If a name doesn't resolve, abort and give a useful error.

If a name resolves to something invalid, abort and give a useful error.
This commit is contained in:
Jimmy Kiselak 2015-09-16 16:27:46 -04:00
parent 4b407a9dd2
commit 8177119671
4 changed files with 39 additions and 5 deletions

View file

@ -71,4 +71,8 @@ class NoSuchBlobError(Exception):
class NoSuchStreamHashError(Exception):
pass
class InvalidBlobHashError(Exception):
pass

View file

@ -141,6 +141,12 @@ class BlobRequester(object):
return [p for p in peers if not p in bad_peers]
d.addCallback(choose_best_peers)
def lookup_failed(err):
log.error("An error occurred looking up peers for a hash: %s", err.getTraceback())
return []
d.addErrback(lookup_failed)
return d
def _should_send_request_to(self, peer):

View file

@ -5,6 +5,9 @@ from lbrynet.core.BlobInfo import BlobInfo
from lbrynet.core.client.BlobRequester import BlobRequester
from lbrynet.core.client.ConnectionManager import ConnectionManager
from lbrynet.core.client.DownloadManager import DownloadManager
from lbrynet.core.Error import InvalidBlobHashError
from lbrynet.core.utils import is_valid_blobhash
from twisted.python.failure import Failure
from twisted.internet import defer
@ -102,6 +105,9 @@ class StandaloneBlobDownloader(object):
self.finished_deferred = None
def download(self):
if not is_valid_blobhash(self.blob_hash):
return defer.fail(Failure(InvalidBlobHashError(self.blob_hash)))
def cancel_download(d):
self.stop()

View file

@ -6,6 +6,7 @@ from lbrynet.lbryfilemanager.LBRYFileCreator import create_lbry_file
from lbrynet.lbryfile.StreamDescriptor import get_sd_info
from lbrynet.lbrynet_console.interfaces import IControlHandler, IControlHandlerFactory
from lbrynet.core.StreamDescriptor import download_sd_blob
from lbrynet.core.Error import UnknownNameError, InvalidBlobHashError
from twisted.internet import defer
@ -164,8 +165,9 @@ class GetWalletBalances(ControlHandler):
d = self.wallet.get_balance()
def format_balance(balance):
balance_string = "id: 1\n"
balance_string += "balance: " + str(balance) + "\n"
if balance == 0:
balance = 0
balance_string = "balance: " + str(balance) + " LBC\n"
return balance_string
d.addCallback(format_balance)
@ -231,7 +233,7 @@ class LBRYFileStatusFactory(ControlHandlerFactory):
class AddStream(ControlHandler):
prompt_description = None
line_prompt = None
cancel_prompt = "Trying to locate the stream descriptor. Type \"cancel\" to cancel."
cancel_prompt = "Trying to locate the stream's metadata. Type \"cancel\" to cancel..."
canceled_message = "Canceled locating the stream descriptor"
line_prompt2 = "Modify options? (y/n)"
line_prompt3 = "Start download? (y/n)"
@ -339,8 +341,8 @@ class AddStream(ControlHandler):
def _handle_load_failed(self, err):
self.loading_failed = True
log.error("An exception occurred attempting to load the stream descriptor: %s", err.getTraceback())
return defer.succeed("Encountered a problem while loading the stream descriptor: %s\n"
"See console.log for further details.\n"
return defer.succeed("An unexpected error occurred attempting to load the stream's metadata.\n"
"See console.log for further details.\n\n"
"Press enter to continue" % err.getErrorMessage())
def _choose_factory(self, info_and_factories):
@ -460,6 +462,12 @@ class AddStreamFromHash(AddStream):
d.addCallback(self.sd_identifier.get_info_and_factories_for_sd_blob)
return d
def _handle_load_failed(self, err):
err.trap(InvalidBlobHashError)
self.loading_failed = True
return defer.succeed("The hash you entered is invalid. It must be 96 characters long and "
"contain only hex characters.\n\nPress enter to continue")
class AddStreamFromHashFactory(ControlHandlerFactory):
control_handler_class = AddStreamFromHash
@ -485,6 +493,16 @@ class AddStreamFromLBRYcrdName(AddStreamFromHash):
d.addCallback(get_name_from_info)
return d
def _handle_load_failed(self, err):
err.trap(UnknownNameError, InvalidBlobHashError)
self.loading_failed = True
if err.check(UnknownNameError):
return defer.succeed("The name %s could not be found.\n\n"
"Press enter to continue" % err.getErrorMessage())
else:
return defer.succeed("The metadata for this name is invalid. The stream cannot be downloaded.\n\n" +
"Press enter to continue")
class AddStreamFromLBRYcrdNameFactory(ControlHandlerFactory):
control_handler_class = AddStreamFromLBRYcrdName