2 # errors.py : exception definitions
4 # Copyright 2007, Red Hat Inc.
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; version 2 of the License.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Library General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 class CreatorError(Exception):
20 """An exception base class for all imgcreate errors."""
21 def __init__(self
, msg
):
22 Exception.__init
__(self
, msg
)
24 # Some error messages may contain unicode strings (especially if your system
25 # locale is different from 'C', e.g. 'de_DE'). Python's exception class does
26 # not handle this appropriately (at least until 2.5) because str(Exception)
27 # returns just self.message without ensuring that all characters can be
28 # represented using ASCII. So we try to return a str and fall back to repr
29 # if this does not work.
31 # Please use unicode for your error logging strings so that we can really
32 # print nice error messages, e.g.:
33 # log.error(u"Internal error: " % e)
35 # log.error("Internal error: " % e)
36 # With our custom __str__ and __unicode__ methods both will work but the
37 # first log call print a more readable error message.
40 return str(self
.message
)
41 except UnicodeEncodeError:
42 return repr(self
.message
)
44 def __unicode__(self
):
47 return unicode(self
.message
.decode("utf8"))
49 class KickstartError(CreatorError
):
51 class MountError(CreatorError
):
53 class SnapshotError(CreatorError
):
55 class SquashfsError(CreatorError
):
57 class ResizeError(CreatorError
):