From 80d7ee3494260fbb02bf1641c289d1af6a6428a9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 5 Jan 2009 10:09:24 -0500 Subject: [PATCH] Added error specific to missing database files. Better than a general assert error. --- text_db.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/text_db.py b/text_db.py index 06d31fc..0d0bf72 100644 --- a/text_db.py +++ b/text_db.py @@ -77,7 +77,8 @@ class text_db (object) : Assert that the database exists on disk. Print a reasonable error if it does not. """ - assert self.exists(), "Missing database file %s" % self.curpath() + if not self.exists(): + raise missingDatabaseFile(self.curpath()) def _open(self) : "Load the database from disk" self._assert_exists() @@ -253,6 +254,13 @@ class text_db (object) : self._records.append(['']*len(self._header)) return record +class missingDatabaseFile (Exception) : + "Specified database file does not exist" + def __init__(self, path): + msg = "Missing database file %s" % path + Exception.__init__(self, msg) + self.path = path + class indexStringError (Exception) : "invalid index string format" pass -- 2.26.2