# AUTOGENERATED! DO NOT EDIT! File to edit: 02_exceptions.ipynb (unless otherwise specified).

__all__ = ['ArgumentsRequired', 'RequestError', 'ProjectDoesNotExist', 'VersionDoesNotExist', 'InvalidProjectVersion']

# Cell

class ArgumentsRequired(Exception):
    '''
    Missing required arguments to class/function
    constructor
    '''
    def __init__(self, *args, **kwargs):
        args = [x for x in list(args) if x != None]
        self.missing = args
        is_or = kwargs.get('is_or')
        if is_or == True:
            first_ = [f"`{x}`" for x in args[:-1]]
            final_ = args[-1]
            msg_start = f'{", ".join(first_)} or `{final_}`'
            msg = f"You must pass {msg_start}. At least one is a required argument."
            self.message = msg
        else:
            msg_start = "".join(args)
            verb = "is a"
            adj = "required"
            noun = "argument"
            if len(args) > 1:
                first_ = [f"`{x}`" for x in args[:-1]]
                final_ = args[-1]
                msg_start = f'{", ".join(first_)} and `{final_}`'
                verb = "are"
                noun = "arguments"
            full_mssage = " ".join([msg_start, verb, adj, noun]).strip()
            self.message = f"{full_mssage}.".strip()
    def __str__(self):
        return repr(self.message)


class RequestError(Exception):
    '''
    General HTTP Request Error
    '''
    def __init__(self, msg, status):
        self.message = msg
        self.status = status
    def __str__(self):
        return repr(f"{self.message} (status {self.status})")


class ProjectDoesNotExist(Exception):
    '''
    Tight.ai project does not exist
    '''
    def __init__(self, project_id=None):
        if project_id != None:
            self.message = f"Project {project_id} is not found, does not exist, or you do not have permission to view."
        self.message = f"This project does not exist."
        self.project_id = project_id
    def __str__(self):
        return repr(f"{self.message}")


class VersionDoesNotExist(Exception):
    '''
    Tight.ai project version does not exist
    '''
    def __init__(self, project_id=None, version=None):
        if project_id != None and version != None:
            self.message = f"The version {version} in project {project_id} is not found, does not exist, or you do not have permission to view."
        self.message = f"This project version does not exist."
        self.project_id = project_id
        self.version = version
    def __str__(self):
        return repr(f"{self.message}")


class InvalidProjectVersion(Exception):
    '''
    Tight.ai project version does not exist
    '''
    error_str = ""
    error = "Unknown"
    def __init__(self, version=None, error=None):
        if f"{error}".lower() == "nan":
            self.error = error
            self.error_str = "NaN (not a number)"
        self.message = f"{version} is invalid."
        if version != None:
            self.message = f"{version} is an invalid version. Error {self.error_str}".strip()
        self.version = version
    def __str__(self):
        return repr(f"{self.message}")

