summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-03 15:35:54 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-01-03 15:35:54 -0700
commitd1517b95ca14773773647434fb589c8224307328 (patch)
tree6e9064d09405795856385a8927e8832f00c41fb2 /ipalib
parent0d3ddef93b0a72b824297e5504e435a4427f14bd (diff)
downloadfreeipa-d1517b95ca14773773647434fb589c8224307328.tar.gz
freeipa-d1517b95ca14773773647434fb589c8224307328.tar.xz
freeipa-d1517b95ca14773773647434fb589c8224307328.zip
Ported errors.SubprocessError to errors2
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/errors2.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/ipalib/errors2.py b/ipalib/errors2.py
index f49c10ef..676dd79f 100644
--- a/ipalib/errors2.py
+++ b/ipalib/errors2.py
@@ -46,6 +46,37 @@ class PrivateError(StandardError):
Base class for exceptions that are *never* returned in an RPC response.
"""
+ format = ''
+
+ def __init__(self, **kw):
+ self.message = self.format % kw
+ for (key, value) in kw.iteritems():
+ assert not hasattr(self, key), 'conflicting kwarg %s.%s = %r' % (
+ self.__class__.__name__, key, value,
+ )
+ setattr(self, key, value)
+ StandardError.__init__(self, self.message)
+
+
+class SubprocessError(PrivateError):
+ """
+ Raised when ``subprocess.call()`` returns a non-zero exit status.
+
+ This custom exception is needed because Python 2.4 doesn't have the
+ ``subprocess.CalledProcessError`` exception (which was added in Python 2.5).
+
+ For example:
+
+ >>> e = SubprocessError(returncode=1, argv=('/bin/false',))
+ >>> e.returncode
+ 1
+ >>> e.argv
+ ('/bin/false',)
+ >>> str(e)
+ "return code 1 from ('/bin/false',)"
+ """
+ format = 'return code %(returncode)d from %(argv)r'
+
class PublicError(StandardError):
"""