Better errors for bad bug roots
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 18 May 2005 19:19:39 +0000 (19:19 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 18 May 2005 19:19:39 +0000 (19:19 +0000)
becommands/set_root.py
libbe/bugdir.py

index 14286e0e2c114581b5035ce07ee6a5e8e6786348..0ec4c02c789353321ebd255d2f6e45a48b4a6928 100644 (file)
@@ -40,6 +40,9 @@ def execute(args):
     >>> bd = bugdir.tree_root(dir.name+"/{arch}")
     >>> bd.root = dir.name
     >>> tests.clean_up()
+    >>> execute(('/highly-unlikely-to-exist',))
+    Traceback (most recent call last):
+    UserError: No such directory: /highly-unlikely-to-exist
     """
     if len(args) != 1:
         raise cmdutil.UserError("Please supply a directory path")
@@ -48,5 +51,8 @@ def execute(args):
         print "Using %s for revision control." % dir_rcs.name
     else:
         print "No revision control detected."
-    bugdir.create_bug_dir(args[0], dir_rcs)
+    try:
+        bugdir.create_bug_dir(args[0], dir_rcs)
+    except bugdir.NoRootEntry:
+        raise cmdutil.UserError("No such directory: %s" % args[0])
     print "Directory initialized."
index ea6384dc43919d6531e22c80ad8a688a49e3ae22..8856db48450c147b2294e0ad42dd7f4057ee1349 100644 (file)
@@ -60,9 +60,25 @@ def set_version(path, rcs):
 
 TREE_VERSION_STRING = "Bugs Everywhere Tree 1 0\n"
 
+class NoRootEntry(Exception):
+    def __init__(self, path):
+        self.path = path
+        Exception.__init__(self, "Specified root does not exist: %s" % path)
+
 def create_bug_dir(path, rcs):
+    """
+    >>> import no_rcs
+    >>> create_bug_dir('/highly-unlikely-to-exist', no_rcs)
+    Traceback (most recent call last):
+    NoRootEntry: Specified root does not exist: /highly-unlikely-to-exist
+    """
     root = os.path.join(path, ".be")
-    rcs.mkdir(root)
+    try:
+        rcs.mkdir(root)
+    except OSError, e:
+        if e.errno != errno.ENOENT:
+            raise
+        raise NoRootEntry(path)
     rcs.mkdir(os.path.join(root, "bugs"))
     set_version(root, rcs)
     map_save(rcs, os.path.join(root, "settings"), {"rcs_name": rcs.name})