]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: use KeyError (rather than IndexError) to signal a missing child
authorBrian Warner <warner@lothar.com>
Sat, 7 Jul 2007 02:40:08 +0000 (19:40 -0700)
committerBrian Warner <warner@lothar.com>
Sat, 7 Jul 2007 02:40:08 +0000 (19:40 -0700)
src/allmydata/dirnode.py
src/allmydata/test/test_dirnode.py

index 7d264ee57839df352844bb80b23cc11856ab980f..418d974ce26958364e892f7a5dc03c02372efea4 100644 (file)
@@ -78,7 +78,7 @@ class VirtualDriveServer(service.MultiService, Referenceable):
         for (H_key, E_key, E_write, E_read) in data[1]:
             if H_key == key:
                 return (E_write, E_read)
-        raise IndexError("unable to find key %s" % idlib.b2a(key))
+        raise KeyError("unable to find key %s" % idlib.b2a(key))
     remote_get = get
 
     def list(self, index):
@@ -97,7 +97,7 @@ class VirtualDriveServer(service.MultiService, Referenceable):
                 del data[1][i]
                 self._write_to_file(index, data)
                 return
-        raise IndexError("unable to find key %s" % idlib.b2a(key))
+        raise KeyError("unable to find key %s" % idlib.b2a(key))
     remote_delete = delete
 
     def set(self, index, write_enabler, key,   name, write, read):
@@ -240,9 +240,9 @@ class ImmutableDirectoryNode:
         H_name = self._hash_name(name)
         d = self._rref.callRemote("get", self._index, H_name)
         def _check_index_error(f):
-            f.trap(IndexError)
-            raise IndexError("get(index=%s): unable to find child named '%s'"
-                             % (idlib.b2a(self._index), name))
+            f.trap(KeyError)
+            raise KeyError("get(index=%s): unable to find child named '%s'"
+                           % (idlib.b2a(self._index), name))
         d.addErrback(_check_index_error)
         d.addCallback(lambda (E_write, E_read):
                       self._decrypt_child(E_write, E_read))
index f3a27c3fa9f019139271876f5ce4338a0d18b7de..1a645e527ba84168371c5323dec51013d3bcdb0e 100644 (file)
@@ -46,7 +46,7 @@ class DirectoryNode(unittest.TestCase):
                              ("write1", "read1"))
         self.failUnlessEqual(vds.get(index, "key2"),
                              ("", "read2"))
-        self.failUnlessRaises(IndexError,
+        self.failUnlessRaises(KeyError,
                               vds.get, index, "key3")
 
         self.failUnlessEqual(sorted(vds.list(index)),
@@ -61,7 +61,7 @@ class DirectoryNode(unittest.TestCase):
                              [ ("name1", "write1", "read1"),
                                ("name2", "", "read2"),
                                ])
-        self.failUnlessRaises(IndexError,
+        self.failUnlessRaises(KeyError,
                               vds.delete,
                               index, we, "key3")
 
@@ -69,7 +69,7 @@ class DirectoryNode(unittest.TestCase):
         self.failUnlessEqual(sorted(vds.list(index)),
                              [ ("name2", "", "read2"),
                                ])
-        self.failUnlessRaises(IndexError,
+        self.failUnlessRaises(KeyError,
                               vds.get, index, "key1")
         self.failUnlessEqual(vds.get(index, "key2"),
                              ("", "read2"))
@@ -197,7 +197,7 @@ class Test(unittest.TestCase):
 
         d.addCallback(lambda res: rootnode.get("missing"))
         # this should raise an exception
-        d.addBoth(self.shouldFail, IndexError, "get('missing')",
+        d.addBoth(self.shouldFail, KeyError, "get('missing')",
                   "unable to find child named 'missing'")
 
         d.addCallback(lambda res: rootnode.create_empty_directory("bar"))