aboutsummaryrefslogtreecommitdiff
path: root/bindings/python/notmuch/database.py
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2012-02-20 23:49:07 +0100
committerJustus Winter <4winter@informatik.uni-hamburg.de>2012-02-20 23:49:07 +0100
commita1442952d4d7fad8b7612502802ee346ac8fd349 (patch)
treedb39fb9e53bd8b1f883c44a64e8b727f0d28beb2 /bindings/python/notmuch/database.py
parent4bb9f59ff6da456392ffaf9871941203e4cf9b53 (diff)
python: refactor the error handling machinery
Raise specific error classes instead of a generic NotmuchError with an magic status value (e.g. NotmuchError(STATUS.NULL_POINTER) -> NullPointerError()), update the documentation accordingly. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
Diffstat (limited to 'bindings/python/notmuch/database.py')
-rw-r--r--bindings/python/notmuch/database.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index 6edb18b..3de0f2b 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -23,7 +23,9 @@ from ctypes import c_char_p, c_void_p, c_uint, c_long, byref, POINTER
from notmuch.globals import (
nmlib,
STATUS,
+ FileError,
NotmuchError,
+ NullPointerError,
NotInitializedError,
Enum,
_str,
@@ -355,9 +357,8 @@ class Database(object):
# we got an absolute path
if not path.startswith(self.get_path()):
# but its initial components are not equal to the db path
- raise NotmuchError(STATUS.FILE_ERROR,
- message="Database().get_directory() called "
- "with a wrong absolute path.")
+ raise FileError('Database().get_directory() called '
+ 'with a wrong absolute path')
abs_dirpath = path
else:
#we got a relative path, make it absolute
@@ -542,7 +543,7 @@ class Database(object):
self._assert_db_is_initialized()
tags_p = Database._get_all_tags(self._db)
if tags_p == None:
- raise NotmuchError(STATUS.NULL_POINTER)
+ raise NullPointerError()
return Tags(tags_p, self)
def create_query(self, querystring):
@@ -636,7 +637,7 @@ class Directory(object):
"""Raises a NotmuchError(:attr:`STATUS`.NOT_INITIALIZED)
if dir_p is None"""
if not self._dir_p:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
def __init__(self, path, dir_p, parent):
"""
@@ -797,7 +798,7 @@ class Filenames(object):
def __next__(self):
if not self._files_p:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
if not self._valid(self._files_p):
self._files_p = None
@@ -824,7 +825,7 @@ class Filenames(object):
for file in files: print file
"""
if not self._files_p:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotInitializedError()
i = 0
while self._valid(self._files_p):