chiark / gitweb /
Make a common superclass for all StGit exceptions
authorKarl Hasselström <kha@treskal.com>
Sun, 7 Oct 2007 13:07:11 +0000 (15:07 +0200)
committerKarl Hasselström <kha@treskal.com>
Sun, 7 Oct 2007 22:14:11 +0000 (00:14 +0200)
This makes it easier to catch them all. (Indeed, the very long list of
exceptions to catch in main.py was missing some of the exceptions.)

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/common.py
stgit/config.py
stgit/exception.py [new file with mode: 0644]
stgit/git.py
stgit/gitmergeonefile.py
stgit/main.py
stgit/run.py
stgit/stack.py
stgit/utils.py

index 0fc157ad7b03e66fac5d82aa098789729d407bc9..27a616ffe1b27a95753d58c24e70ce0e6a0013f9 100644 (file)
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 import sys, os, os.path, re
 from optparse import OptionParser, make_option
 
+from stgit.exception import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git, basedir
@@ -30,11 +31,11 @@ crt_series = None
 
 
 # Command exception class
-class CmdException(Exception):
+class CmdException(StgException):
     pass
 
 # Utility functions
-class RevParseException(Exception):
+class RevParseException(StgException):
     """Revision spec parse error."""
     pass
 
index 51818bd37c2977dba2552cb292605cfd15618923..3eabc8c3a3abef4be9586d933ff573efe0dd7e17 100644 (file)
@@ -20,9 +20,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 import os, re
 from stgit import basedir
+from stgit.exception import *
 from stgit.run import *
 
-class GitConfigException(Exception):
+class GitConfigException(StgException):
     pass
 
 class GitConfig:
diff --git a/stgit/exception.py b/stgit/exception.py
new file mode 100644 (file)
index 0000000..9933e64
--- /dev/null
@@ -0,0 +1,3 @@
+class StgException(Exception):
+    """Base class for all StGit exceptions."""
+    pass
index a0493bcda827667c70bced6e87f72c46055aae46..0026fd86fe1969aed5625d96f10ff4b34f60d91d 100644 (file)
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 import sys, os, re, gitmergeonefile
 from shutil import copyfile
 
+from stgit.exception import *
 from stgit import basedir
 from stgit.utils import *
 from stgit.out import *
@@ -28,7 +29,7 @@ from stgit.run import *
 from stgit.config import config
 
 # git exception class
-class GitException(Exception):
+class GitException(StgException):
     pass
 
 # When a subprocess has a problem, we want the exception to be a
index 2aa5ef8042d0352a3477699be354ab4c33dd1929..058b6ac4dec8d09939c5887df88381859396baa4 100644 (file)
@@ -19,13 +19,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
+from stgit.exception import *
 from stgit import basedir
 from stgit.config import config, file_extensions, ConfigOption
 from stgit.utils import append_string
 from stgit.out import *
 from stgit.run import *
 
-class GitMergeException(Exception):
+class GitMergeException(StgException):
     pass
 
 
index 2c8716b2d850c070597c1b4ca987a299c7b69330..f54330d3e4f6dc12fa7cd2e1173f73b892884192 100644 (file)
@@ -255,13 +255,10 @@ def main():
 
     # These modules are only used from this point onwards and do not
     # need to be imported earlier
+    from stgit.exception import StgException
     from stgit.config import config_setup
     from ConfigParser import ParsingError, NoSectionError
-    from stgit.stack import Series, StackException
-    from stgit.git import GitException
-    from stgit.commands.common import CmdException
-    from stgit.gitmergeonefile import GitMergeException
-    from stgit.utils import EditorException
+    from stgit.stack import Series
 
     try:
         debug_level = int(os.environ['STGIT_DEBUG_LEVEL'])
@@ -284,9 +281,7 @@ def main():
             stgit.commands.common.crt_series = command.crt_series
 
         command.func(parser, options, args)
-    except (IOError, ParsingError, NoSectionError, CmdException,
-            StackException, GitException, GitMergeException,
-            EditorException), err:
+    except (StgException, IOError, ParsingError, NoSectionError), err:
         print >> sys.stderr, '%s %s: %s' % (prog, cmd, err)
         if debug_level > 0:
             raise
index 7986f3b04e33d2d24d420eda7e7d88b1932e54d2..989bb27a33026f1c82dd31c4a5b37f73a2c2a148 100644 (file)
@@ -19,9 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 import datetime, os, subprocess
 
-from  stgit.out import *
+from stgit.exception import *
+from stgit.out import *
 
-class RunException(Exception):
+class RunException(StgException):
     """Thrown when something bad happened when we tried to run the
     subprocess."""
     pass
index 4d1a066001d0bd45ba7055ab1e9cda958459629f..bdb4e38a5834a9c93c251733c7c1d19ebcbf493a 100644 (file)
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 import sys, os, re
 from email.Utils import formatdate
 
+from stgit.exception import *
 from stgit.utils import *
 from stgit.out import *
 from stgit.run import *
@@ -30,7 +31,7 @@ from shutil import copyfile
 
 
 # stack exception class
-class StackException(Exception):
+class StackException(StgException):
     pass
 
 class FilterUntil:
index 857c0f0986c05c7dc49624087ba579e809091385..3a480c0e6d9d9a2c0323fca3aaa789fd96068f08 100644 (file)
@@ -2,6 +2,7 @@
 """
 
 import errno, optparse, os, os.path, re, sys
+from stgit.exception import *
 from stgit.config import config
 from stgit.out import *
 
@@ -166,7 +167,7 @@ def rename(basedir, file1, file2):
         # file1's parent dir may not be empty after move
         pass
 
-class EditorException(Exception):
+class EditorException(StgException):
     pass
 
 def call_editor(filename):