From 43989122bbb4b94b6d0d0647349a43fe9106aac1 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 6 Aug 2021 12:55:33 -0300 Subject: [PATCH] add error type and message to error readme and update code --- lbry/error/README.md | 3 ++- lbry/error/__init__.py | 15 ++++++++------- lbry/wallet/server/db/elasticsearch/search.py | 4 ++-- lbry/wallet/server/session.py | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lbry/error/README.md b/lbry/error/README.md index 4af499334..352c903f4 100644 --- a/lbry/error/README.md +++ b/lbry/error/README.md @@ -53,10 +53,11 @@ Code | Name | Message 407 | DataDownload | Failed to download blob. *generic* 410 | Resolve | Failed to resolve '{url}'. 411 | ResolveTimeout | Failed to resolve '{url}' within the timeout. -411 | ResolveCensored | Resolve of '{url}' was censored by channel with claim id '{claim_id(censor_hash)}'. +411 | ResolveCensored | Resolve of '{url}' was censored by channel with claim id '{censor_id}'. 420 | KeyFeeAboveMaxAllowed | {message} 421 | InvalidPassword | Password is invalid. 422 | IncompatibleWalletServer | '{server}:{port}' has an incompatibly old version. +423 | TooManyClaimSearchParameters | {key} cant be set for more than {limit} items. 431 | ServerPaymentInvalidAddress | Invalid address from wallet server: '{address}' - skipping payment round. 432 | ServerPaymentWalletLocked | Cannot spend funds with locked wallet, skipping payment round. 433 | ServerPaymentFeeAboveMaxAllowed | Daily server fee of {daily_fee} exceeds maximum configured of {max_fee} LBC. diff --git a/lbry/error/__init__.py b/lbry/error/__init__.py index bf255ec06..9b66a20f2 100644 --- a/lbry/error/__init__.py +++ b/lbry/error/__init__.py @@ -234,13 +234,6 @@ class InvalidPasswordError(WalletError): super().__init__("Password is invalid.") -class TooManyClaimSearchParameters(WalletError): - - def __init__(self, key, limit): - self.key = key - super().__init__(f"{key} cant be set for more than {limit} items.") - - class IncompatibleWalletServerError(WalletError): def __init__(self, server, port): @@ -249,6 +242,14 @@ class IncompatibleWalletServerError(WalletError): super().__init__(f"'{server}:{port}' has an incompatibly old version.") +class TooManyClaimSearchParametersError(WalletError): + + def __init__(self, key, limit): + self.key = key + self.limit = limit + super().__init__(f"{key} cant be set for more than {limit} items.") + + class ServerPaymentInvalidAddressError(WalletError): def __init__(self, address): diff --git a/lbry/wallet/server/db/elasticsearch/search.py b/lbry/wallet/server/db/elasticsearch/search.py index 6ce93c617..1dc0d8707 100644 --- a/lbry/wallet/server/db/elasticsearch/search.py +++ b/lbry/wallet/server/db/elasticsearch/search.py @@ -10,7 +10,7 @@ from elasticsearch import AsyncElasticsearch, NotFoundError, ConnectionError from elasticsearch.helpers import async_streaming_bulk from lbry.crypto.base58 import Base58 -from lbry.error import ResolveCensoredError, TooManyClaimSearchParameters +from lbry.error import ResolveCensoredError, TooManyClaimSearchParametersError from lbry.schema.result import Outputs, Censor from lbry.schema.tags import clean_tags from lbry.schema.url import URL, normalize_name @@ -466,7 +466,7 @@ def expand_query(**kwargs): key = key.replace('claim.', '') many = key.endswith('__in') or isinstance(value, list) if many and len(value) > 2048: - raise TooManyClaimSearchParameters(key, 2048) + raise TooManyClaimSearchParametersError(key, 2048) if many: key = key.replace('__in', '') value = list(filter(None, value)) diff --git a/lbry/wallet/server/session.py b/lbry/wallet/server/session.py index 06d380c30..a0a4ae0d5 100644 --- a/lbry/wallet/server/session.py +++ b/lbry/wallet/server/session.py @@ -21,7 +21,7 @@ from elasticsearch import ConnectionTimeout from prometheus_client import Counter, Info, Histogram, Gauge import lbry -from lbry.error import TooManyClaimSearchParameters +from lbry.error import TooManyClaimSearchParametersError from lbry.build_info import BUILD, COMMIT_HASH, DOCKER_TAG from lbry.wallet.server.block_processor import LBRYBlockProcessor from lbry.wallet.server.db.writer import LBRYLevelDB @@ -1029,7 +1029,7 @@ class LBRYElectrumX(SessionBase): if kwargs: try: return await self.run_and_cache_query('search', kwargs) - except TooManyClaimSearchParameters as err: + except TooManyClaimSearchParametersError as err: self.loop.call_later(0, self.synchronous_close) return RPCError(1, str(err))