summaryrefslogtreecommitdiff
path: root/larch
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-05-05 12:37:33 +0100
committerLars Wirzenius <liw@liw.fi>2012-05-05 12:37:33 +0100
commit8d79fbfc0b7f8447f60c04f6f65d5b07c9528267 (patch)
tree74199e360d8d3d41dc4993cfb1a8137db9d827f1 /larch
parent045fafc02508d1c7ff1c7a8f37f254ccf024f149 (diff)
downloadlarch-8d79fbfc0b7f8447f60c04f6f65d5b07c9528267.tar.gz
Make all exceptions be subclasses of new class larch.Error
Diffstat (limited to 'larch')
-rw-r--r--larch/__init__.py6
-rw-r--r--larch/codec.py5
-rw-r--r--larch/forest.py19
-rwxr-xr-xlarch/fsck.py5
-rw-r--r--larch/journal.py8
-rw-r--r--larch/nodes.py7
-rw-r--r--larch/nodestore.py35
-rw-r--r--larch/nodestore_disk.py5
-rw-r--r--larch/nodestore_disk_tests.py4
-rw-r--r--larch/tree.py20
10 files changed, 39 insertions, 75 deletions
diff --git a/larch/__init__.py b/larch/__init__.py
index 1c8d274..ef1885a 100644
--- a/larch/__init__.py
+++ b/larch/__init__.py
@@ -17,6 +17,12 @@
__version__ = '0.30'
+class Error(Exception):
+
+ def __str__(self):
+ return self.msg
+
+
from nodes import FrozenNode, Node, LeafNode, IndexNode
from codec import NodeCodec, CodecError
from tree import BTree, KeySizeMismatch, ValueTooLarge
diff --git a/larch/codec.py b/larch/codec.py
index a4bd92f..aa086ab 100644
--- a/larch/codec.py
+++ b/larch/codec.py
@@ -19,9 +19,10 @@ import struct
import larch
-class CodecError(Exception):
+class CodecError(larch.Error):
- '''Exception for decoding errors for nodes.'''
+ def __init__(self, msg):
+ self.msg = msg
class NodeCodec(object):
diff --git a/larch/forest.py b/larch/forest.py
index 2443da1..1ee4575 100644
--- a/larch/forest.py
+++ b/larch/forest.py
@@ -19,37 +19,24 @@ import tracing
import larch
-class MetadataMissingKey(Exception):
+class MetadataMissingKey(larch.Error):
def __init__(self, key_name):
self.msg = 'larch forest metadata missing "%s"' % key_name
- def __str__(self): # pragma: no cover
- return self.msg
-
-class BadKeySize(Exception):
-
- '''Exception for a bad key size.'''
+class BadKeySize(larch.Error):
def __init__(self, store_key_size, wanted_key_size):
self.msg = ('Node store has key size %s, program wanted %s' %
(store_key_size, wanted_key_size))
-
- def __str__(self):
- return self.msg
-class BadNodeSize(Exception):
-
- '''Exception for a bad node size.'''
+class BadNodeSize(larch.Error):
def __init__(self, store_node_size, wanted_node_size):
self.msg = ('Node store has node size %s, program wanted %s' %
(store_node_size, wanted_node_size))
-
- def __str__(self):
- return self.msg
class Forest(object):
diff --git a/larch/fsck.py b/larch/fsck.py
index a47e77c..88243fa 100755
--- a/larch/fsck.py
+++ b/larch/fsck.py
@@ -22,13 +22,10 @@ import ttystatus
import larch
-class Error(Exception):
+class Error(larch.Error):
def __init__(self, msg):
self.msg = 'Assertion failed: %s' % msg
-
- def __str__(self):
- return self.msg
class WorkItem(object):
diff --git a/larch/journal.py b/larch/journal.py
index 7be6212..51d866d 100644
--- a/larch/journal.py
+++ b/larch/journal.py
@@ -19,11 +19,13 @@ import logging
import os
import tracing
+import larch
-class ReadOnlyMode(Exception): # pragma: no cover
- def __str__(self):
- return 'Larch B-tree is in read-only mode, no changes allowed'
+class ReadOnlyMode(larch.Error): # pragma: no cover
+
+ def __init__(self):
+ self.msg = 'Larch B-tree is in read-only mode, no changes allowed'
class Journal(object):
diff --git a/larch/nodes.py b/larch/nodes.py
index ffcfab6..e480fff 100644
--- a/larch/nodes.py
+++ b/larch/nodes.py
@@ -19,15 +19,12 @@ import bisect
import larch
-class FrozenNode(Exception):
+class FrozenNode(larch.Error):
'''User tried to modify node that is frozen.'''
def __init__(self, node):
- self.node = node
-
- def __str__(self):
- return 'Node %s is frozen against modifications' % self.node.id
+ self.msg = 'Node %s is frozen against modifications' % node.id
class Node(object):
diff --git a/larch/nodestore.py b/larch/nodestore.py
index 40f0ff3..82bcfbc 100644
--- a/larch/nodestore.py
+++ b/larch/nodestore.py
@@ -17,53 +17,38 @@
import larch
-class NodeMissing(Exception): # pragma: no cover
+class NodeMissing(larch.Error):
'''A node cannot be found from a NodeStore.'''
def __init__(self, node_store, node_id):
- self.node_store = node_store
- self.node_id = node_id
-
- def __str__(self):
- return ('Node %d cannot be found in the node store %s' %
- (self.node_id, self.node_store))
+ self.msg = ('Node %d cannot be found in the node store %s' %
+ (node_id, node_store))
-class NodeTooBig(Exception): # pragma: no cover
+class NodeTooBig(larch.Error):
'''User tried to put a node that was too big into the store.'''
def __init__(self, node, node_size):
- self.node_type = node.__class__.__name__
- self.node_id = node.id
- self.node_size = node_size
-
- def __str__(self):
- return ('%s %d is too big (%d bytes)' %
- (self.node_type, self.node_id, self.node_size))
+ self.msg = ('%s %d is too big (%d bytes)' %
+ (node.__class__.__name__, node.id, node_size))
-class NodeExists(Exception): # pragma: no cover
+class NodeExists(larch.Error):
'''User tried to put a node that already exists in the store.'''
def __init__(self, node_id):
- self.node_id = node_id
+ self.msg = 'Node %d is already in the store' % node_id
- def __str__(self):
- return 'Node %d is already in the store' % self.node_id
-
-class NodeCannotBeModified(Exception): # pragma: no cover
+class NodeCannotBeModified(larch.Error):
'''User called start_modification on node that cannot be modified.'''
def __init__(self, node_id):
- self.node_id = node_id
-
- def __str__(self):
- return 'Node %d cannot be modified' % self.node_id
+ self.msg = 'Node %d cannot be modified' % node_id
class NodeStore(object): # pragma: no cover
diff --git a/larch/nodestore_disk.py b/larch/nodestore_disk.py
index 57d0795..11f48b5 100644
--- a/larch/nodestore_disk.py
+++ b/larch/nodestore_disk.py
@@ -30,13 +30,10 @@ DIR_BITS = 12
DIR_SKIP = 13
-class FormatProblem(Exception): # pragma: no cover
+class FormatProblem(larch.Error): # pragma: no cover
def __init__(self, msg):
self.msg = msg
-
- def __str__(self):
- return self.msg
class LocalFS(object): # pragma: no cover
diff --git a/larch/nodestore_disk_tests.py b/larch/nodestore_disk_tests.py
index 7f22c31..0d3bb05 100644
--- a/larch/nodestore_disk_tests.py
+++ b/larch/nodestore_disk_tests.py
@@ -53,13 +53,13 @@ class NodeStoreDiskTests(unittest.TestCase, larch.NodeStoreTests):
old = self.new_ns(format=0)
old.save_metadata()
new = self.new_ns(format=1)
- self.assertRaises(Exception, new.get_metadata, 'format')
+ self.assertRaises(larch.Error, new.get_metadata, 'format')
def test_refuses_to_open_if_format_version_is_not_there(self):
self.ns.remove_metadata('format')
self.ns.save_metadata()
ns2 = self.new_ns()
- self.assertRaises(Exception, ns2.get_metadata, 'format')
+ self.assertRaises(larch.Error, ns2.get_metadata, 'format')
def test_has_persistent_metadata(self):
self.ns.set_metadata('foo', 'bar')
diff --git a/larch/tree.py b/larch/tree.py
index f9a382f..614542e 100644
--- a/larch/tree.py
+++ b/larch/tree.py
@@ -23,30 +23,22 @@ import larch
'''A simple B-tree implementation.'''
-class KeySizeMismatch(Exception):
+class KeySizeMismatch(larch.Error):
'''User tried to use key of wrong size.'''
def __init__(self, key, wanted_size):
- self.key = key
- self.wanted_size = wanted_size
-
- def __str__(self):
- return 'Key %s is of wrong length (%d, should be %d)' % \
- (repr(self.key), len(self.key), self.wanted_size)
+ self.msg = ('Key %s is of wrong length (%d, should be %d)' %
+ (repr(key), len(key), wanted_size))
-class ValueTooLarge(Exception):
+class ValueTooLarge(larch.Error):
'''User tried ot use a vlaue htat is too large for a node.'''
def __init__(self, value, max_size):
- self.value = value
- self.max_size = max_size
-
- def __str__(self):
- return 'Value %s is too long (%d, max %d)' % \
- (repr(self.value), len(self.value), self.max_size)
+ self.msg = ('Value %s is too long (%d, max %d)' %
+ (repr(value), len(value), max_size))
class BTree(object):