aboutsummaryrefslogtreecommitdiff
path: root/fingerd/errors.py
blob: 791c971337de8ce3d7e747629700eb57b479c7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# *****************************************************************************
# Copyright (C) 2017-2021 Thomas Touhey <thomas@touhey.fr>
# This file is part of the fingerd project, which is MIT-licensed.
# *****************************************************************************
""" This file defines the exceptions used throughout the module. """

__all__ = [
    'BindError', 'ConfigurationError', 'HostnameError',
    'InvalidBindError', 'MalformedQueryError', 'NoBindsError',
]

# ---
# Configuration-related errors.
# ---


class ConfigurationError(Exception):
    """ Raised when an invalid configuration option is set. """

    pass


class HostnameError(ConfigurationError):
    """ Raised when a host name is invalid. """

    def __init__(self, hostname):
        super().__init__('invalid host name {}.'.format(repr(hostname)))


class BindError(ConfigurationError):
    """ Raised when an error has occurred with the provided binds. """

    def __init__(self, msg):
        super().__init__(
            f'an error has occurred with the provided binds: {msg}')


class NoBindsError(BindError):
    """ Raised when no binds were provided. """

    def __init__(self):
        super().__init__('no valid bind')


class InvalidBindError(BindError):
    """ Raised when one of the provided binds came out erroneous. """

    def __init__(self, bind, msg=None):
        super().__init__(
            f'one of the provided bind ({bind!r}) '
            f'was invalid{": " + msg if msg else ""}',
        )


class MalformedQueryError(Exception):
    """ Raised when a malformed query is received. """

    def __init__(self, query, msg=None):
        self.query = query
        self.msg = msg

        super().__init__(
            msg + (f': {query!r}' if query else '') + '.',
        )

# End of file.