from inspect import currentframe, getframeinfo
"""
This file contains custom errors for the exam generator.
"""
[docs]class MissingDirectoryError(Exception):
"""
Error raised when a needed directory is missing.
:param info: errorInfo()
:type info: func
:param directory: missing directory
:type directory: str. Default None.
"""
def __init__(self, info, directory=None):
self.info = info
self.file = directory
[docs]class MissingFileError(Exception):
"""
Error raised when a needed file is missing.
:param info: errorInfo()
:type info: func
:param file: missing file name
:type file: str
"""
def __init__(self, info, file=None):
self.info = info
self.file = file
[docs]class SettingsError(Exception):
"""
Error raised when there is a problem with user input.
:param info: errorInfo()
:type info: func
:param settings_file: name of settings file
:type settings_file: str
"""
def __init__(self, info, settings_file=None):
self.info = info
self.settings_file = settings_file
[docs]class CompilingError(Exception):
"""
Error raised when there is a problem during the compiling process.
:param info: errorInfo()
:type info: func
:param file: name of file where compiling failed
:type file: str. Defaulted to None
"""
def __init__(self, info, extra_info=None):
self.info = info
self.file = extra_info
[docs]class PoolError(Exception):
"""
Error raised when something went wrong during pool creation
:param pool: errorInfo()
:type info: func
:param pool: name of the affected pool
:type pool: str
"""
def __int__(self, pool, info):
self.info = f"Pool {pool}: {info}"
[docs]def errorInfo():
"""
Gives information about the origin of the raised error.
:returns: Line of error + file
:rtype: str
"""
cf = currentframe()
return f"Error in line {cf.f_back.f_lineno}:"