Version 18.3
[livecd.git] / imgcreate / errors.py
blob800dc3bcb65fa87c88596654ee000bb21f2a41b4
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)
34 # instead of
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.
38 def __str__(self):
39 try:
40 return str(self.message)
41 except UnicodeEncodeError:
42 return repr(self.message)
44 def __unicode__(self):
45 return unicode(self.message)
47 class KickstartError(CreatorError):
48 pass
49 class MountError(CreatorError):
50 pass
51 class SnapshotError(CreatorError):
52 pass
53 class SquashfsError(CreatorError):
54 pass
55 class ResizeError(CreatorError):
56 pass