From 21376a824071928cfb82afcbffc0db60b82751de Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 24 Feb 2013 17:49:52 +0000 Subject: Improve error messages for missing nodes --- NEWS | 1 + larch/nodestore.py | 6 ++---- larch/nodestore_disk.py | 6 +++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 02d4494..3eea7c2 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ Version UNRELEASED `NodeStore` and `NodeStoreMemory` now have a new first argument, `allow_writes`, to make them compatible with the `NodeStoreDisk` initialiser. Patch by Antoine Brenner. +* Improved error messages for nodes that seem to be missing. Version 1.20121216 ------------------ diff --git a/larch/nodestore.py b/larch/nodestore.py index dd9b536..70bcc93 100644 --- a/larch/nodestore.py +++ b/larch/nodestore.py @@ -21,10 +21,8 @@ class NodeMissing(larch.Error): '''A node cannot be found from a NodeStore.''' - def __init__(self, node_store, node_id, error=None): - if error is None: - error_msg = '' - else: + def __init__(self, node_store, node_id, error=None, error_msg=''): + if error is not None: error_msg = (': %s: %s: %s' % (error.errno, error.strerror, error.filename)) self.msg = ('Node %s cannot be found in the node store %s%s' % diff --git a/larch/nodestore_disk.py b/larch/nodestore_disk.py index 6e8cd2f..dec41e1 100644 --- a/larch/nodestore_disk.py +++ b/larch/nodestore_disk.py @@ -258,7 +258,11 @@ class NodeStoreDisk(larch.NodeStore): if self.journal.exists(name): self.journal.remove(name) elif not got_it: - raise larch.NodeMissing(self.dirname, node_id) + raise larch.NodeMissing( + self.dirname, + node_id, + error_msg='attempted to remove node that is not ' + 'in journal or in upload queue') def list_nodes(self): queued = self.upload_queue.list_ids() -- cgit v1.2.1