2 # errors.py: Kickstart error handling.
4 # Chris Lumens <clumens@redhat.com>
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
21 Error handling classes and functions.
23 This module exports a single function:
25 formatErrorMsg - Properly formats an error message.
27 It also exports several exception classes:
29 KickstartError - A generic exception class.
31 KickstartParseError - An exception for errors relating to parsing.
33 KickstartValueError - An exception for errors relating to option
36 KickstartVersionError - An exception for errors relating to unsupported
39 from rhpl
.translate
import _
40 import rhpl
.translate
as translate
42 translate
.textdomain("pykickstart")
44 def formatErrorMsg(lineno
, msg
=""):
45 """Properly format the error message msg for inclusion in an exception."""
47 mapping
= {"lineno": lineno
, "msg": msg
}
48 return _("The following problem occurred on line %(lineno)s of the kickstart file:\n\n%(msg)s\n") % mapping
50 return _("There was a problem reading from line %s of the kickstart file") % lineno
52 class KickstartError(Exception):
53 """A generic exception class for unspecific error conditions."""
54 def __init__(self
, val
= ""):
55 """Create a new KickstartError exception instance with the descriptive
56 message val. val should be the return value of formatErrorMsg.
58 Exception.__init
__(self
)
64 class KickstartParseError(KickstartError
):
65 """An exception class for errors when processing the input file, such as
66 unknown options, commands, or sections.
68 def __init__(self
, msg
):
69 """Create a new KickstartParseError exception instance with the
70 descriptive message val. val should be the return value of
73 KickstartError
.__init
__(self
, msg
)
78 class KickstartValueError(KickstartError
):
79 """An exception class for errors when processing arguments to commands,
80 such as too many arguments, too few arguments, or missing required
83 def __init__(self
, msg
):
84 """Create a new KickstartValueError exception instance with the
85 descriptive message val. val should be the return value of
88 KickstartError
.__init
__(self
, msg
)
93 class KickstartVersionError(KickstartError
):
94 """An exception class for errors related to using an incorrect version of
97 def __init__(self
, msg
):
98 """Create a new KickstartVersionError exception instance with the
99 descriptive message val. val should be the return value of
102 KickstartError
.__init
__(self
, msg
)