Brisppy / twitch-archiver

A simple, fast, platform-independent tool for downloading Twitch streams, videos, and chat logs.
GNU Affero General Public License v3.0
61 stars 6 forks source link

Question about custom Exception implementation #16

Closed HeliosLHC closed 1 year ago

HeliosLHC commented 1 year ago

Hi @Brisppy,

I'm looking through some of the exceptions in exceptions.py and noticed that the following format is used for custom exceptions.

class ChatExportError(Exception):
    def __init__(self, error):
        self.message = f'Chat export failed. Error: {error}'

From looking at the code, nothing appears (please correct me if I'm wrong) to read the "message" attribute of these custom exceptions nor are these messages printed out console output when the custom exceptions are raised. The custom formatted strings in the exceptions don't appear to be used or output.

The "message" attribute for exceptions appear to be deprecated in Python 3.0.

Does there happen to be an intended use for the "message" attribute in the custom exception?

Brisppy commented 1 year ago

I'm not too familiar with how to properly implement custom exceptions so this is just what I went with because it worked - The 'message' attribute is included in the traceback so I was just using it to give some sort of understandable output on an exception.

Traceback (most recent call last):
  File "/opt/twitch-archiver/src/processing.py", line 202, in get_vod_connector
    raise VodMergeError('VOD length outside of acceptable range. If error persists delete '
src.exceptions.VodMergeError: VOD length outside of acceptable range. If error persists delete 'vod/parts' directory if VOD still available.

Nevermind it seems I was using outdated info and they're not included at all so will just remove them. If there's a more accepted way of doing custom exceptions though I'm open to suggestions.

HeliosLHC commented 1 year ago

Thanks for clarification, this syntax perhaps may be better suited instead:

class CustomException(Exception):
    "Raised when a certain event occurs"
    def __init__(self, arg1, arg2):

        message = f"formatted message here: {arg1} {arg2}"
        super().__init__(message)