use previous exception insted of declaring a new one

This commit is contained in:
Victor Shyba 2020-09-14 11:53:13 -03:00
parent 2a0089a4dd
commit a554c8838c
4 changed files with 10 additions and 16 deletions

View file

@ -15,7 +15,7 @@ import zmq.asyncio
from lbry.conf import Config from lbry.conf import Config
from lbry.event import EventController from lbry.event import EventController
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError, LbrycrdMisconfigurationError from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError
from .database import BlockchainDB from .database import BlockchainDB
from .ledger import Ledger, RegTestLedger from .ledger import Ledger, RegTestLedger
@ -209,8 +209,6 @@ class Lbrycrd:
async def ensure_subscribable(self): async def ensure_subscribable(self):
zmq_notifications = await self.get_zmq_notifications() zmq_notifications = await self.get_zmq_notifications()
if not zmq_notifications:
raise LbrycrdMisconfigurationError("zmqpubhashblock")
subs = {e['type']: e['address'] for e in zmq_notifications} subs = {e['type']: e['address'] for e in zmq_notifications}
if ZMQ_BLOCK_EVENT not in subs: if ZMQ_BLOCK_EVENT not in subs:
raise LbrycrdEventSubscriptionError(ZMQ_BLOCK_EVENT) raise LbrycrdEventSubscriptionError(ZMQ_BLOCK_EVENT)

View file

@ -10,9 +10,9 @@ from lbry.db.query_context import Event, Progress
from lbry.event import BroadcastSubscription from lbry.event import BroadcastSubscription
from lbry.service.base import Sync, BlockEvent from lbry.service.base import Sync, BlockEvent
from lbry.blockchain.lbrycrd import Lbrycrd from lbry.blockchain.lbrycrd import Lbrycrd
from lbry.error import LbrycrdEventSubscriptionError
from . import blocks as block_phase, claims as claim_phase, supports as support_phase from . import blocks as block_phase, claims as claim_phase, supports as support_phase
from ...error import LbrycrdMisconfigurationError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -49,8 +49,11 @@ class BlockchainSync(Sync):
return await self.chain.ensure_subscribable() return await self.chain.ensure_subscribable()
except asyncio.CancelledError: except asyncio.CancelledError:
raise raise
except LbrycrdMisconfigurationError as e: except LbrycrdEventSubscriptionError as e:
log.warning(str(e)) log.warning(
"Lbrycrd is misconfigured. Please double check if"
" zmqpubhashblock is properly set on lbrycrd.conf"
)
raise raise
except Exception as e: except Exception as e:
log.warning("Blockchain not ready, waiting for it: %s", str(e)) log.warning("Blockchain not ready, waiting for it: %s", str(e))

View file

@ -417,10 +417,3 @@ class LbrycrdEventSubscriptionError(LbrycrdError):
def __init__(self, event): def __init__(self, event):
self.event = event self.event = event
super().__init__(f"Lbrycrd is not publishing '{event}' events.") super().__init__(f"Lbrycrd is not publishing '{event}' events.")
class LbrycrdMisconfigurationError(LbrycrdError):
def __init__(self, config_key):
self.config_key = config_key
super().__init__(f"Lbrycrd is misconfigured. Please double check if"
f" {config_key} is properly set on lbrycrd.conf")

View file

@ -11,7 +11,7 @@ from lbry import Config, Database, RegTestLedger, Transaction, Output, Input
from lbry.crypto.base58 import Base58 from lbry.crypto.base58 import Base58
from lbry.schema.claim import Stream, Channel from lbry.schema.claim import Stream, Channel
from lbry.schema.support import Support from lbry.schema.support import Support
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError, LbrycrdMisconfigurationError from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError
from lbry.blockchain.lbrycrd import Lbrycrd from lbry.blockchain.lbrycrd import Lbrycrd
from lbry.blockchain.sync import BlockchainSync from lbry.blockchain.sync import BlockchainSync
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
@ -304,7 +304,7 @@ class TestLbrycrdAPIs(AsyncioTestCase):
# lbrycrdr started without zmq # lbrycrdr started without zmq
await chain.start() await chain.start()
with self.assertRaises(LbrycrdMisconfigurationError): with self.assertRaises(LbrycrdEventSubscriptionError):
await chain.ensure_subscribable() await chain.ensure_subscribable()
await chain.stop() await chain.stop()
@ -620,7 +620,7 @@ class TestGeneralBlockchainSync(SyncingBlockchainTestCase):
await asyncio.sleep(0) await asyncio.sleep(0)
self.chain.ledger.conf.set(lbrycrd_zmq_blocks='') self.chain.ledger.conf.set(lbrycrd_zmq_blocks='')
await self.chain.start() await self.chain.start()
with self.assertRaises(LbrycrdMisconfigurationError): with self.assertRaises(LbrycrdEventSubscriptionError):
await asyncio.wait_for(sync_start, timeout=10) await asyncio.wait_for(sync_start, timeout=10)
await self.chain.stop() await self.chain.stop()