better error detection in _get_stream_info_from_value
This commit is contained in:
parent
9535a24706
commit
39b47bc569
4 changed files with 15 additions and 12 deletions
|
@ -53,11 +53,12 @@ class InvalidStreamDescriptorError(Exception):
|
|||
|
||||
|
||||
class InvalidStreamInfoError(Exception):
|
||||
def __init__(self, name):
|
||||
def __init__(self, name, stream_info):
|
||||
self.name = name
|
||||
self.stream_info = stream_info
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.name)
|
||||
return '{} has claim with invalid stream info: {}'.format(self.name,self.stream_info)
|
||||
|
||||
|
||||
class MisbehavingPeerError(Exception):
|
||||
|
|
|
@ -344,8 +344,8 @@ class Wallet(object):
|
|||
|
||||
try:
|
||||
metadata = Metadata(json.loads(result['value']))
|
||||
except ValidationError:
|
||||
return Failure(InvalidStreamInfoError(name))
|
||||
except (TypeError,ValueError,ValidationError):
|
||||
return Failure(InvalidStreamInfoError(name,result['value']))
|
||||
|
||||
txid = result['txid']
|
||||
sd_hash = metadata['sources']['lbry_sd_hash']
|
||||
|
@ -427,7 +427,7 @@ class Wallet(object):
|
|||
meta_ver = metadata.version
|
||||
sd_hash = metadata['sources']['lbry_sd_hash']
|
||||
d = self._save_name_metadata(name, txid, sd_hash)
|
||||
except ValidationError:
|
||||
except (TypeError,ValueError,ValidationError):
|
||||
metadata = claim['value']
|
||||
meta_ver = "Non-compliant"
|
||||
d = defer.succeed(None)
|
||||
|
|
|
@ -900,7 +900,7 @@ class AddStreamFromLBRYcrdName(AddStreamFromHash):
|
|||
def _resolve_name(self, name):
|
||||
def get_name_from_info(stream_info):
|
||||
if 'stream_hash' not in stream_info:
|
||||
raise InvalidStreamInfoError(name)
|
||||
raise InvalidStreamInfoError(name,stream_info)
|
||||
self.resolved_name = stream_info.get('name', None)
|
||||
self.description = stream_info.get('description', None)
|
||||
try:
|
||||
|
|
|
@ -33,6 +33,8 @@ class Metadata(StructuredDict):
|
|||
]
|
||||
|
||||
def __init__(self, metadata, migrate=True, target_version=None):
|
||||
if not isinstance(metadata,dict):
|
||||
raise TypeError("metadata is not a dictionary")
|
||||
starting_version = metadata.get('ver', '0.0.1')
|
||||
|
||||
StructuredDict.__init__(self, metadata, starting_version, migrate, target_version)
|
Loading…
Reference in a new issue