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
40 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
42 def formatErrorMsg(lineno
, msg
=""):
43 """Properly format the error message msg for inclusion in an exception."""
45 mapping
= {"lineno": lineno
, "msg": msg
}
46 return _("The following problem occurred on line %(lineno)s of the kickstart file:\n\n%(msg)s\n") % mapping
48 return _("There was a problem reading from line %s of the kickstart file") % lineno
50 class KickstartError(Exception):
51 """A generic exception class for unspecific error conditions."""
52 def __init__(self
, val
= ""):
53 """Create a new KickstartError exception instance with the descriptive
54 message val. val should be the return value of formatErrorMsg.
56 Exception.__init
__(self
)
62 class KickstartParseError(KickstartError
):
63 """An exception class for errors when processing the input file, such as
64 unknown options, commands, or sections.
66 def __init__(self
, msg
):
67 """Create a new KickstartParseError exception instance with the
68 descriptive message val. val should be the return value of
71 KickstartError
.__init
__(self
, msg
)
76 class KickstartValueError(KickstartError
):
77 """An exception class for errors when processing arguments to commands,
78 such as too many arguments, too few arguments, or missing required
81 def __init__(self
, msg
):
82 """Create a new KickstartValueError exception instance with the
83 descriptive message val. val should be the return value of
86 KickstartError
.__init
__(self
, msg
)
91 class KickstartVersionError(KickstartError
):
92 """An exception class for errors related to using an incorrect version of
95 def __init__(self
, msg
):
96 """Create a new KickstartVersionError exception instance with the
97 descriptive message val. val should be the return value of
100 KickstartError
.__init
__(self
, msg
)