Total Complexity | 1 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """ |
||
2 | PRIVATE MODULE: do not import (from) it directly. |
||
3 | |||
4 | This module contains the ``jacked`` error classes. |
||
5 | """ |
||
6 | import inspect |
||
7 | from typing import Union |
||
8 | |||
9 | |||
10 | class JackedError(Exception): |
||
11 | """ |
||
12 | Base class for all ``jacked`` errors. |
||
13 | """ |
||
14 | |||
15 | |||
16 | class InvalidUsageError(JackedError): |
||
17 | """ |
||
18 | Raised when ``jacked`` was used in the wrong manner (e.g. decorating a |
||
19 | class with ``@inject``). |
||
20 | """ |
||
21 | |||
22 | |||
23 | class InjectionError(JackedError): |
||
24 | """ |
||
25 | Raised when injection failed. |
||
26 | """ |
||
27 | def __init__(self, msg: str, subject: Union[inspect.Parameter, type]): |
||
28 | """ |
||
29 | Constructor. |
||
30 | :param msg: the message of the error. |
||
31 | :param subject: a parameter in case of a decorator injection, a type in |
||
32 | case of ``inject_here`` was used. |
||
33 | """ |
||
34 | super(InjectionError, self).__init__(msg) |
||
35 | self.subject = subject |
||
36 |