diff --git a/lbry/error/README.md b/lbry/error/README.md index 403227ebf..3244bf76d 100644 --- a/lbry/error/README.md +++ b/lbry/error/README.md @@ -36,6 +36,8 @@ Code | Name | Message 112 | InputValueIsNone | None or null is not valid value for argument '{argument}'. 113 | ConflictingInputValue | Only '{first_argument}' or '{second_argument}' is allowed, not both. 114 | InputStringIsBlank | {argument} cannot be blank. +115 | EmptyPublishedFile | Cannot publish empty file: {file_path} +116 | MissingPublishedFile | File does not exist: {file_path} **2xx** | Configuration | Configuration errors. 201 | ConfigWrite | Cannot write configuration file '{path}'. -- When writing the default config fails on startup, such as due to permission issues. 202 | ConfigRead | Cannot find provided configuration file '{path}'. -- Can't open the config file user provided via command line args. diff --git a/lbry/error/__init__.py b/lbry/error/__init__.py index b8a3d14ef..34056a78d 100644 --- a/lbry/error/__init__.py +++ b/lbry/error/__init__.py @@ -91,6 +91,20 @@ class InputStringIsBlankError(InputValueError): super().__init__(f"{argument} cannot be blank.") +class EmptyPublishedFileError(InputValueError): + + def __init__(self, file_path): + self.file_path = file_path + super().__init__(f"Cannot publish empty file: {file_path}") + + +class MissingPublishedFileError(InputValueError): + + def __init__(self, file_path): + self.file_path = file_path + super().__init__(f"File does not exist: {file_path}") + + class ConfigurationError(BaseError): """ Configuration errors. diff --git a/lbry/schema/attrs.py b/lbry/schema/attrs.py index 4b0973ac3..522dc3413 100644 --- a/lbry/schema/attrs.py +++ b/lbry/schema/attrs.py @@ -10,6 +10,7 @@ from google.protobuf.json_format import MessageToDict from lbry.crypto.base58 import Base58 from lbry.constants import COIN +from lbry.error import MissingPublishedFileError, EmptyPublishedFileError from lbry.schema.mime_types import guess_media_type from lbry.schema.base import Metadata, BaseMessageList @@ -139,10 +140,10 @@ class Source(Metadata): self.name = os.path.basename(file_path) self.media_type, stream_type = guess_media_type(file_path) if not os.path.isfile(file_path): - raise Exception(f"File does not exist: {file_path}") + raise MissingPublishedFileError(file_path) self.size = os.path.getsize(file_path) if self.size == 0: - raise Exception(f"Cannot publish empty file: {file_path}") + raise EmptyPublishedFileError(file_path) self.file_hash_bytes = calculate_sha384_file_hash(file_path) return stream_type