Coverage for mymeco/exceptions.py: 100%
15 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-01-15 20:56 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-01-15 20:56 +0000
1# coding: utf-8
2"""Top Level exceptions module raised by Mymeco."""
3import typing
6class MymecoError(Exception):
7 """
8 All exception raised by Mymeco should inherit this base class.
10 >>> MymecoError('Generic Error')
11 MymecoError: Generic Error
13 >>> print(MymecoError('Unexpected behaviour'))
14 Unexpected behaviour
15 """
17 def __init__(self: typing.Self, message: str) -> None:
18 """
19 Build a standard Mymeco exception.
21 :param message: Human readable information on exception.
22 Message should help end-user to understand why such error occurs,
23 and possibly some hints on how to solve issue.
24 """
25 super().__init__()
26 self.message = message
28 def __repr__(self: typing.Self) -> str:
29 """Give detailed information on error."""
30 return f'{self.__class__.__name__}: {self.message}'
32 def __str__(self: typing.Self) -> str:
33 """Give human readable description on error."""
34 return self.message
37class NoConfigurationFile(MymecoError):
38 """
39 Raise when no configuration file is available.
41 >>> NoConfigurationFile()
42 NoConfigurationFile: No configuration file was found on your system.
43 """
45 def __init__(self: typing.Self) -> None:
46 """Build a missing configuration file exception."""
47 super().__init__('No configuration file was found on your system.')
50class MissingConfiguration(MymecoError):
51 """
52 Raise when a necessary configuration entry is not found.
54 >>> MissingConfiguration('section', 'key', 'file')
55 MissingConfiguration: [section].key is not found in file
56 """
58 def __init__(self: typing.Self,
59 section: str,
60 key: typing.Optional[str],
61 filename: str) -> None:
62 """
63 Build a MissingConfiguration exception.
65 :param section: Name of section with missing entry
66 :param key: Name of missing key in section. Could be None if even the
67 given section is not found.
68 :param filename: Configuration filename used in this context.
69 """
70 super().__init__(f'[{section}].{key} is not found in {filename}')