mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 15:16:41 +00:00
web: use KeyError (rather than IndexError) to signal a missing child
This commit is contained in:
parent
a34040df99
commit
71c04fc2e7
@ -78,7 +78,7 @@ class VirtualDriveServer(service.MultiService, Referenceable):
|
|||||||
for (H_key, E_key, E_write, E_read) in data[1]:
|
for (H_key, E_key, E_write, E_read) in data[1]:
|
||||||
if H_key == key:
|
if H_key == key:
|
||||||
return (E_write, E_read)
|
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
|
remote_get = get
|
||||||
|
|
||||||
def list(self, index):
|
def list(self, index):
|
||||||
@ -97,7 +97,7 @@ class VirtualDriveServer(service.MultiService, Referenceable):
|
|||||||
del data[1][i]
|
del data[1][i]
|
||||||
self._write_to_file(index, data)
|
self._write_to_file(index, data)
|
||||||
return
|
return
|
||||||
raise IndexError("unable to find key %s" % idlib.b2a(key))
|
raise KeyError("unable to find key %s" % idlib.b2a(key))
|
||||||
remote_delete = delete
|
remote_delete = delete
|
||||||
|
|
||||||
def set(self, index, write_enabler, key, name, write, read):
|
def set(self, index, write_enabler, key, name, write, read):
|
||||||
@ -240,9 +240,9 @@ class ImmutableDirectoryNode:
|
|||||||
H_name = self._hash_name(name)
|
H_name = self._hash_name(name)
|
||||||
d = self._rref.callRemote("get", self._index, H_name)
|
d = self._rref.callRemote("get", self._index, H_name)
|
||||||
def _check_index_error(f):
|
def _check_index_error(f):
|
||||||
f.trap(IndexError)
|
f.trap(KeyError)
|
||||||
raise IndexError("get(index=%s): unable to find child named '%s'"
|
raise KeyError("get(index=%s): unable to find child named '%s'"
|
||||||
% (idlib.b2a(self._index), name))
|
% (idlib.b2a(self._index), name))
|
||||||
d.addErrback(_check_index_error)
|
d.addErrback(_check_index_error)
|
||||||
d.addCallback(lambda (E_write, E_read):
|
d.addCallback(lambda (E_write, E_read):
|
||||||
self._decrypt_child(E_write, E_read))
|
self._decrypt_child(E_write, E_read))
|
||||||
|
@ -46,7 +46,7 @@ class DirectoryNode(unittest.TestCase):
|
|||||||
("write1", "read1"))
|
("write1", "read1"))
|
||||||
self.failUnlessEqual(vds.get(index, "key2"),
|
self.failUnlessEqual(vds.get(index, "key2"),
|
||||||
("", "read2"))
|
("", "read2"))
|
||||||
self.failUnlessRaises(IndexError,
|
self.failUnlessRaises(KeyError,
|
||||||
vds.get, index, "key3")
|
vds.get, index, "key3")
|
||||||
|
|
||||||
self.failUnlessEqual(sorted(vds.list(index)),
|
self.failUnlessEqual(sorted(vds.list(index)),
|
||||||
@ -61,7 +61,7 @@ class DirectoryNode(unittest.TestCase):
|
|||||||
[ ("name1", "write1", "read1"),
|
[ ("name1", "write1", "read1"),
|
||||||
("name2", "", "read2"),
|
("name2", "", "read2"),
|
||||||
])
|
])
|
||||||
self.failUnlessRaises(IndexError,
|
self.failUnlessRaises(KeyError,
|
||||||
vds.delete,
|
vds.delete,
|
||||||
index, we, "key3")
|
index, we, "key3")
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class DirectoryNode(unittest.TestCase):
|
|||||||
self.failUnlessEqual(sorted(vds.list(index)),
|
self.failUnlessEqual(sorted(vds.list(index)),
|
||||||
[ ("name2", "", "read2"),
|
[ ("name2", "", "read2"),
|
||||||
])
|
])
|
||||||
self.failUnlessRaises(IndexError,
|
self.failUnlessRaises(KeyError,
|
||||||
vds.get, index, "key1")
|
vds.get, index, "key1")
|
||||||
self.failUnlessEqual(vds.get(index, "key2"),
|
self.failUnlessEqual(vds.get(index, "key2"),
|
||||||
("", "read2"))
|
("", "read2"))
|
||||||
@ -197,7 +197,7 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
d.addCallback(lambda res: rootnode.get("missing"))
|
d.addCallback(lambda res: rootnode.get("missing"))
|
||||||
# this should raise an exception
|
# 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'")
|
"unable to find child named 'missing'")
|
||||||
|
|
||||||
d.addCallback(lambda res: rootnode.create_empty_directory("bar"))
|
d.addCallback(lambda res: rootnode.create_empty_directory("bar"))
|
||||||
|
Loading…
Reference in New Issue
Block a user