Source code for poppy.core.tools.exceptions

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import traceback
import logging

from poppy.core.logger import logger
import sys


__all__ = ["DescriptorLoadError",
            "MissingArgument",
           "MissingProperty",
           "MissingInput",
           "TargetFileNotSaved",
            "print_exception",
            "exception_hook"]

[docs]def exception_hook(exctype, value, traceback): """Tailored version of the excepthook can be used to only print full traceback in DEBUG mode. To activate it, add the line sys.excepthook = exception_hook in the code. See https://stackoverflow.com/questions/6598053/python-global-exception-handling/6598286#6598286""" if logger.getEffectiveLevel() == logging.DEBUG: sys.__excepthook__(exctype, value, traceback)
[docs]class DescriptorLoadError(Exception): """Exception raised when a descriptor file cannot be loaded.""" def __init__(self, message, *args, **kwargs): super(DescriptorLoadError, self).__init__(*args, **kwargs) logger.error(message) self.message = message pass
[docs]class MissingInput(Exception): """Exception raised if an input target is missing.""" def __init__(self, message, *args, **kwargs): super(MissingInput, self).__init__(*args, **kwargs) logger.error(message) self.message = message pass
[docs]class MissingArgument(Exception): """ Exception raised when input argument is missing """ def __init__(self, message, *args, **kwargs): super(MissingArgument, self).__init__(*args, **kwargs) logger.error(message) self.message = message pass
[docs]class MissingProperty(Exception): """Exception raised if a pipeline property is missing.""" def __init__(self, message, *args, **kwargs): super(MissingProperty, self).__init__(*args, **kwargs) logger.error(message) self.message = message pass
[docs]class TargetFileNotSaved(Exception): """Exception raised if target file not saved correctly.""" def __init__(self, message, *args, **kwargs): super(TargetFileNotSaved, self).__init__(*args, **kwargs) logger.error(message) self.message = message pass