[Pkg-bazaar-commits] ./bzr/unstable r599: - better error reporting from smart_add

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:20:06 UTC 2009


------------------------------------------------------------
revno: 599
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-05-30 15:10:41 +1000
message:
  - better error reporting from smart_add
modified:
  bzrlib/add.py
  bzrlib/errors.py
-------------- next part --------------
=== modified file 'bzrlib/add.py'
--- a/bzrlib/add.py	2005-05-30 03:35:20 +0000
+++ b/bzrlib/add.py	2005-05-30 05:10:41 +0000
@@ -17,7 +17,6 @@
 import os, sys
 import bzrlib
 
-from errors import bailout
 from trace import mutter, note
 
 def smart_add(file_list, verbose=True, recurse=True):
@@ -27,7 +26,8 @@
     For the specific behaviour see the help for cmd_add().
     """
     from bzrlib.osutils import quotefn, kind_marker
-    
+    from bzrlib.errors import BadFileKindError, ForbiddenFileError
+
     assert file_list
     user_list = file_list[:]
     assert not isinstance(file_list, basestring)
@@ -43,15 +43,16 @@
         kind = bzrlib.osutils.file_kind(af)
 
         if kind != 'file' and kind != 'directory':
-            if f not in user_list:
-                print "Skipping %s (can't add file of kind '%s')" % (f, kind)
+            if f in user_list:
+                raise BadFileKindError("cannot add %s of type %s" % (f, kind))
+            else:
+                print "skipping %s (can't add file of kind '%s')" % (f, kind)
                 continue
-            bailout("can't add file of kind %r" % kind)
 
         bzrlib.mutter("smart add of %r, abs=%r" % (f, af))
         
         if bzrlib.branch.is_control_file(af):
-            bailout("cannot add control file %r" % af)
+            raise ForbiddenFileError('cannot add control file %s' % f)
             
         versioned = (inv.path2id(rf) != None)
 

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2005-05-27 04:07:05 +0000
+++ b/bzrlib/errors.py	2005-05-30 05:10:41 +0000
@@ -39,6 +39,18 @@
     pass
 
 
+class BadFileKindError(BzrError):
+    """Specified file is of a kind that cannot be added.
+
+    (For example a symlink or device file.)"""
+    pass
+
+
+class ForbiddenFileError(BzrError):
+    """Cannot operate on a file because it is a control file."""
+    pass
+
+
 def bailout(msg, explanation=[]):
     ex = BzrError(msg, explanation)
     import trace



More information about the Pkg-bazaar-commits mailing list