Skip to content

Commit

Permalink
file_manager: trap the exception if the claim is not a stream
Browse files Browse the repository at this point in the history
If `claim` is not a stream, the line `claim.stream.source.bt_infohash`
will raise a `ValueError` exception because `claim.stream`
does not contain a valid object.

This will happen if we try to download a claim
that is in fact a `collection` (a playlist).
```
lbrynet get collection-music
```

Since at the moment we don't trap this exception, it prints
the entire trace of the exception.
```
Traceback (most recent call last):
  File "/opt/git/lbry-sdk/lbry/file/file_manager.py", line 117, in download_from_uri
    if claim.stream.source.bt_infohash:
  File "/opt/git/lbry-sdk/lbry/schema/claim.py", line 55, in stream
    return Stream(self)
  File "/opt/git/lbry-sdk/lbry/schema/claim.py", line 108, in __init__
    self.message = self.claim.get_message(self.claim_type)
  File "/opt/git/lbry-sdk/lbry/schema/claim.py", line 46, in get_message
    raise ValueError(f'Claim is not a {type_name}.')
```

Therefore we will raise `InvalidStreamURLError` if `claim.is_collection` is True
or if `claim.is_stream` is False.

Later on the code we handle this `InvalidStreamURLError` exception
to show the appropriate message.
```
WARNING  lbry.file.file_manager:258: Failed to download collection-music:
Invalid LBRY stream URL: 'collection-music'
WARNING  lbry.extras.daemon.daemon:1114:
Error downloading collection-music: Claim is not a stream.
```
  • Loading branch information
belikor committed Sep 4, 2021
1 parent e79e779 commit b53360d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lbry/file/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ async def download_from_uri(self, uri, exchange_rate_manager: 'ExchangeRateManag
resolved_time = self.loop.time() - start_time
await self.storage.save_claim_from_output(self.wallet_manager.ledger, txo)

if claim.is_collection:
raise InvalidStreamURLError(uri)
if not claim.is_stream:
raise InvalidStreamURLError(uri)

####################
# update or replace
####################
Expand Down

0 comments on commit b53360d

Please sign in to comment.