From: Brian Warner Date: Sat, 7 Jul 2007 02:40:08 +0000 (-0700) Subject: web: use KeyError (rather than IndexError) to signal a missing child X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=71c04fc2e703437cda1f72021dacccdf5f425455;p=tahoe-lafs%2Ftahoe-lafs.git web: use KeyError (rather than IndexError) to signal a missing child --- diff --git a/src/allmydata/dirnode.py b/src/allmydata/dirnode.py index 7d264ee5..418d974c 100644 --- a/src/allmydata/dirnode.py +++ b/src/allmydata/dirnode.py @@ -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)) diff --git a/src/allmydata/test/test_dirnode.py b/src/allmydata/test/test_dirnode.py index f3a27c3f..1a645e52 100644 --- a/src/allmydata/test/test_dirnode.py +++ b/src/allmydata/test/test_dirnode.py @@ -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"))