from django.core import exceptions as django_exception from celery import exceptions as celery_exceptions class ScriptAuditException(Exception): """ A base Exception class for NeturalAudit. """ def __init__(self, error_msg=None) -> None: super().__init__(error_msg) class ScriptAuditTaskException(ScriptAuditException): """ A base Exception class for NeturalAudit Task. """ def __init__(self, error_msg) -> None: if not error_msg: error_msg = "Some error occured during execution!" super().__init__(error_msg) class ScriptIdNotFound(ScriptAuditException): """ Raised when script_id is not provided. """ def __init__(self) -> None: super().__init__( "script_id must be provided as keyword-argument in delay." ) class AlreadyAudited(ScriptAuditTaskException): """ Raised when script is already audited. """ def __init__(self, script_id) -> None: super().__init__(f"Script {script_id} Already exists and is Audited... ") class AlreadyRunning(ScriptAuditTaskException): """ Raised when audit for given scrpit is already running. """ def __init__(self, script_id) -> None: super().__init__(f"Audit is already Running for Script {script_id}") class ScriptDoesNotExist( ScriptAuditException, django_exception.ObjectDoesNotExist ): """ Raised when object of script_model is not found in MNFScriptDatabase_2. """ def __init__(self, script_id) -> None: super().__init__( f"Script with script_id : {script_id} does not exists." ) class ScriptAuditModelDoesNotExist( ScriptAuditTaskException, django_exception.ObjectDoesNotExist ): """ Raised when object of Script Audit Model is not found in MNFScriptDatabase_2. """ def __init__(self, celery_id) -> None: super().__init__( f"Script Audit Model with celery_id : {celery_id} does not exists." ) class TimeLimitExeded( celery_exceptions.SoftTimeLimitExceeded ): """ Raised when Softtime limit exceeds. This exception is raised to give the task a chance to clean up. """ def __init__(self, soft_time_limit : int) -> None: super().__init__( f"Time limit of {soft_time_limit}sec exeded." ) class IllegalFiletype(ScriptAuditTaskException, django_exception.ObjectDoesNotExist): """ Raise whien specified file type is not allowed. """ def __init__(self, file_type: str, valid_types: tuple) -> None: err_msg: str = f"Provide file type `{file_type}` is not supported. Valid types are {', ' .join(valid_types)}" super().__init__(err_msg)