Passed
Pull Request — master (#134)
by
unknown
01:55
created

gvm.errors.InvalidArgument.__init__()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2018 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
"""
19
Module for GVM errors
20
"""
21
22
23
class GvmError(Exception):
24
    """An exception for gvm errors
25
26
    Base class for all exceptions originating in python-gvm.
27
    """
28
29
30
class InvalidArgument(GvmError):
31
    """Raised if an invalid argument/parameter is passed
32
33
    Derives from :py:class:`GvmError`
34
35
    Attributes:
36
        message (str, optional): Error message to be displayed. Takes precedence
37
            over argument and function
38
        argument (str, optional): Optional name of the invalid argument
39
        function (str, optional): Optional name of the called function
40
    """
41
42
    def __init__(self, message=None, *, argument=None, function=None):
43
        # pylint: disable=super-init-not-called
44
        self.message = message
45
        self.argument = argument
46
        self.function = function
47
48 View Code Duplication
    def __str__(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
49
        if self.message:
50
            return self.message
51
52
        if not self.function:
53
            return "Invalid argument {}".format(self.argument)
54
55
        if not self.argument:
56
            return "Invalid argument for {}".format(self.function)
57
58
        return "Invalid argument {} for {}".format(self.argument, self.function)
59
60
61
class RequiredArgument(GvmError):
62
    """Raised if a required argument/parameter is missing
63
64
    Derives from :py:class:`GvmError`
65
66
    Attributes:
67
        message (str): Error message to be displayed
68
        argument (str, optional): Optional name of the required argument
69
        function (str, optional): Optional name of the called function
70
    """
71
72
    def __init__(self, message=None, argument=None, function=None):
73
        # pylint: disable=super-init-not-called
74
        self.message = message
75
        self.argument = argument
76
        self.function = function
77
78 View Code Duplication
    def __str__(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
79
        if self.message:
80
            return self.message
81
82
        if not self.function:
83
            return "Required argument {}".format(self.argument)
84
85
        if not self.argument:
86
            return "Required argument missing for {}".format(self.function)
87
88
        return "{} requires a {} argument".format(self.function, self.argument)
89