[docs]classNotFoundError(Exception):""" NotFoundError ============= Exception raised when a resource is not found. Parameters ---------- message : str Error message. """def__init__(self,message:str):self.message=messagesuper().__init__(self.message)
## *** ALREADY EXISTS ERROR *** ##
[docs]classAlreadyExistsError(Exception):""" AlreadyExistsError ================== Exception raised when a resource already exists. Parameters ---------- message : str Error message. """def__init__(self,message:str):self.message=messagesuper().__init__(self.message)
[docs]deferror_parser(error:str)->str:""" Error Parser ============ Function to parse an error message. Parameters ---------- error : str Error message. Returns ------- error_str : str Parsed error message. """# Convert the error to a stringerror=repr(error)# Check if error uses ' or "if"('"inerror:error_str=error.replace("('",": ").replace("')","")# Replace ' with :elif"(\""inerror:error_str=error.replace("(\"",": ").replace("\")","")# Replace " with :else:error_str=error# Return the errorreturnerror_str
## *** ARGS HANDLING *** ##
[docs]defargs_handling(init:bool,**kwargs):""" Args Handling ============= Function to handle the arguments. Parameters ---------- init : bool If the function is called from the __init__ method. **kwargs : dict Keyword arguments. Raises ------ TypeError If all values are not of type `str`. If `TAGS` is not of type `list`. If all values in `TAGS` are not of type `str`. NotFoundError If the folder does not exist. """# Values without TAGSvalues=[value[1]forvalueinkwargs.items()ifvalue[0]!="TAGS"]# Check if all values are stringsifnotall(isinstance(value,str)forvalueinvalues):raiseTypeError("ERROR [VideoService]: All values must be of type 'str'")ifinit:ifnotall(os.path.exists(value)forvalueinvalues):raiseNotFoundError("ERROR [VideoService]: The folder does not exist")# Check if TAGS is in kwargsifkwargs.get("TAGS"):# Check if TAGS is a listifnotisinstance(kwargs.get("TAGS"),list):raiseTypeError("ERROR [VideoService]: 'TAGS' must be of type 'list'")# Check if all values in TAGS are stringsifnotall(isinstance(tag,str)fortaginkwargs.get("TAGS")):raiseTypeError("ERROR [VideoService]: All values in 'TAGS' must be of type 'str'")