2 # errors.py: Kickstart error handling.
4 # Chris Lumens <clumens@redhat.com>
6 # Copyright 2005, 2006 Red Hat, Inc.
8 # This software may be freely redistributed under the terms of the GNU
9 # general public license.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 Error handling classes and functions.
18 This module exports a single function:
20 formatErrorMsg - Properly formats an error message.
22 It also exports several exception classes:
24 KickstartError - A generic exception class.
26 KickstartParseError - An exception for errors relating to parsing.
28 KickstartValueError - An exception for errors relating to option
31 KickstartVersionError - An exception for errors relating to unsupported
34 from rhpl
.translate
import _
35 import rhpl
.translate
as translate
37 translate
.textdomain("pykickstart")
39 def formatErrorMsg(lineno
, msg
=""):
40 """Properly format the error message msg for inclusion in an exception."""
42 mapping
= {"lineno": lineno
, "msg": msg
}
43 return _("The following problem occurred on line %(lineno)s of the kickstart file:\n\n%(msg)s\n") % mapping
45 return _("There was a problem reading from line %s of the kickstart file") % lineno
47 class KickstartError(Exception):
48 """A generic exception class for unspecific error conditions."""
49 def __init__(self
, val
= ""):
50 """Create a new KickstartError exception instance with the descriptive
51 message val. val should be the return value of formatErrorMsg.
53 Exception.__init
__(self
)
59 class KickstartParseError(KickstartError
):
60 """An exception class for errors when processing the input file, such as
61 unknown options, commands, or sections.
63 def __init__(self
, msg
):
64 """Create a new KickstartParseError exception instance with the
65 descriptive message val. val should be the return value of
68 KickstartError
.__init
__(self
, msg
)
73 class KickstartValueError(KickstartError
):
74 """An exception class for errors when processing arguments to commands,
75 such as too many arguments, too few arguments, or missing required
78 def __init__(self
, msg
):
79 """Create a new KickstartValueError exception instance with the
80 descriptive message val. val should be the return value of
83 KickstartError
.__init
__(self
, msg
)
88 class KickstartVersionError(KickstartError
):
89 """An exception class for errors related to using an incorrect version of
92 def __init__(self
, version
):
93 """Create a new KickstartVersionError exception instance with the
94 descriptive message val. val should be the return value of
97 KickstartError
.__init
__(self
, _("Unsupported version specified."))