Source code for mymeco.exceptions

# coding: utf-8
"""Top Level exceptions module raised by Mymeco."""
import typing


MymecoErrorType = typing.TypeVar('MymecoErrorType', bound='MymecoError')


[docs] class MymecoError(BaseException): """ All exception raised by Mymeco should inherit this base class. >>> MymecoError('Generic Error') MymecoError: Generic Error >>> print(MymecoError('Unexpected behaviour')) Unexpected behaviour """ def __init__(self: MymecoErrorType, message: str) -> None: """ Build a standard Mymeco exception. :param message: Human readable information on exception. Message should help end-user to understand why such error occurs, and possibly some hints on how to solve issue. """ super().__init__() self.message = message def __repr__(self: MymecoErrorType) -> str: """Give detailed information on error.""" return '{}: {}'.format(self.__class__.__name__, self.message) def __str__(self: MymecoErrorType) -> str: """Give human readable description on error.""" return self.message
[docs] class NoConfigurationFile(MymecoError): """ Raise when no configuration file is available. >>> NoConfigurationFile() NoConfigurationFile: No configuration file was found on your system. """ def __init__(self) -> None: """Build a missing configuration file exception.""" super().__init__('No configuration file was found on your system.')
[docs] class MissingConfiguration(MymecoError): """ Raise when a necessary configuration entry is not found. >>> MissingConfiguration('section', 'key', 'file') MissingConfiguration: [section].key is not found in file """ def __init__(self, section: str, key: typing.Optional[str], filename: str) -> None: """ Build a MissingConfiguration exception. :param section: Name of section with missing entry :param key: Name of missing key in section. Could be None if even the given section is not found. :param filename: Configuration filename used in this context. """ super().__init__('[{}].{} is not found in {}'.format( section, key, filename))