# ########################################## #
#              Backend exceptions            #
# ########################################## #
class BackendException(BaseException):
    """
        This is the superclass of all the exceptions raised in the
        l1test backend. 
    """
    def get_prefix_message(self) -> str:
        """
            Returns the title to be shown in the error view. 
            The current title is "Cannot run L1Test : ". 

            If it returns `None` so the old title will be kept. 
            Otherwise, it will be changed to the returned value.
        """
        return None

class EmptyValueError(BackendException, ValueError):
    """
    Exception raised when a value is empty. 
    """
    pass

class CompilationError(BackendException): 
    """
    Exception raised when the parsing by the AST parser, `exec()` or by the `compile()` is failed.
    """
    pass

class NoTestFoundException(BackendException):
    """
    Exception raised when an there's no test in the source code. 
    """
    def get_prefix_message(self):
        return ""   
    
class NoFunctionSelectedToTestException(BackendException):
    """
    Exception raised when the selected line doesn't contain a function/class signature.
    """
    pass 

class CannotImportModuleException(BackendException):
    """
    Exception raised when a module cannot be imported by the importlib library.
    """
    pass

class RuntimeException(BackendException):
    """
    Exception raised when a runtime error is raised by the `exec()` method
    """
    pass

class DoctestParserException(BackendException):
    """
    This should be a superclass of all the exceptions raised by the doctest parser
    """
    def __init__(self, filename, lineno, message):
        super().__init__('File %s, line %s\n%s' % (filename, lineno, message))

class SpaceMissingAfterPromptException(DoctestParserException):
    """
    Exception raised when a <space> charatcer is missing after the L1test symbol ($$$) 
    """
    def __init__(self, filename, lineno, invite_sans_blanc):
        super().__init__(filename, lineno, 
                    'A space is missing\n after the prompt : %s' % (invite_sans_blanc)) 
            
            
# ########################################## #
#              Frontend exceptions           #
# ########################################## #
class FrontendException(BaseException):
    """
        This is the superclass of all the exceptions not raised in the
        l1test backend. 
    """
    pass

class NoEditorFoundException(FrontendException):
    """
    exception which includes all exceptions related to the code editor.
    """
    pass
        
class NotSavedFileException(FrontendException):
    """
    Exception raised when the source code is not saved yet on the disk. 
    """
    pass

class EmptyEditorException(FrontendException):
    """
    Exception raised when an editor is still empty. 
    """
    pass

class NoFunctionSelectedToDocumentException(FrontendException):
    """
    Exception raised when no function is selected to document. 
    """
    pass

class DocGeneratorParserException(FrontendException):
    """
    Exception raised when no docstring cannot be generated by the generator.
    This exception is raised when a function signature contains a compilation
    error.
    """
    pass

class CannotSelectSeveralLines(FrontendException):
    """
    Exception raised when several lines are selected. For example, This exception 
    is raised when the user tries to select several lines to run the tests of the selected
    lines. Or, when a user tries to select several lines to generate the docstring.
    """
    pass
