From: Brian Warner Date: Thu, 7 Jun 2007 19:38:22 +0000 (-0700) Subject: hashtree.BadHashError: mention which leaf caused the problem X-Git-Tag: allmydata-tahoe-0.3.0~22 X-Git-Url: https://git.rkrishnan.org/module-simplejson.tests.html?a=commitdiff_plain;h=a383c174448f612c10736dc87e9d1cac471aaa35;p=tahoe-lafs%2Ftahoe-lafs.git hashtree.BadHashError: mention which leaf caused the problem --- diff --git a/src/allmydata/hashtree.py b/src/allmydata/hashtree.py index 3694b91b..31c78757 100644 --- a/src/allmydata/hashtree.py +++ b/src/allmydata/hashtree.py @@ -304,6 +304,14 @@ class IncompleteHashTree(CompleteBinaryTreeMixin, list): maybe_needed.add(self.first_leaf_num + leafnum) return set([i for i in maybe_needed if self[i] is None]) + def _name_hash(self, i): + name = "[%d of %d]" % (i, len(self)) + if i >= self.first_leaf_num: + leafnum = i - self.first_leaf_num + numleaves = len(self) - self.first_leaf_num + name += " (leaf [%d] of %d)" % (leafnum, numleaves) + return name + def set_hashes(self, hashes={}, leaves={}): """Add a bunch of hashes to the tree. @@ -376,7 +384,9 @@ class IncompleteHashTree(CompleteBinaryTreeMixin, list): for i in new_hashes: if self[i]: if self[i] != new_hashes[i]: - raise BadHashError("new hash does not match existing hash at [%d]" % i) + msg = "new hash does not match existing hash at " + msg += self._name_hash(i) + raise BadHashError(msg) else: self[i] = new_hashes[i] added.add(i)