diff options
author | Simo Sorce <simo@redhat.com> | 2015-04-07 18:39:01 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-04-07 18:48:32 -0400 |
commit | 6e5a83f9d9ed80268ba29b1d2404f5d9897fe0c0 (patch) | |
tree | 6492c5f6f353fd727f834208b42949656d270a01 | |
parent | bdac4205f9467f752b5a8e3f424bfd82e67d7b9c (diff) | |
download | custodia-6e5a83f9d9ed80268ba29b1d2404f5d9897fe0c0.tar.gz custodia-6e5a83f9d9ed80268ba29b1d2404f5d9897fe0c0.tar.xz custodia-6e5a83f9d9ed80268ba29b1d2404f5d9897fe0c0.zip |
Add explicit exception for storage conflicts
-rw-r--r-- | custodia/store/interface.py | 4 | ||||
-rw-r--r-- | custodia/store/sqlite.py | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/custodia/store/interface.py b/custodia/store/interface.py index 3c7d620..5a7db93 100644 --- a/custodia/store/interface.py +++ b/custodia/store/interface.py @@ -5,6 +5,10 @@ class CSStoreError(Exception): pass +class CSStoreExists(Exception): + pass + + class CSStore(object): def get(self, key): diff --git a/custodia/store/sqlite.py b/custodia/store/sqlite.py index 481313e..f321678 100644 --- a/custodia/store/sqlite.py +++ b/custodia/store/sqlite.py @@ -1,7 +1,7 @@ # Copyright (C) 2015 Custodia Project Contributors - see LICENSE file from __future__ import print_function -from custodia.store.interface import CSStore, CSStoreError +from custodia.store.interface import CSStore, CSStoreError, CSStoreExists import os import sqlite3 import sys @@ -54,6 +54,8 @@ class SqliteStore(CSStore): c = conn.cursor() self._create(c) c.execute(setdata, (key, value)) + except sqlite3.IntegrityError as err: + raise CSStoreExists(str(err)) except sqlite3.Error as err: log_error("Error storing key %s: [%r]" % (key, repr(err))) raise CSStoreError('Error occurred while trying to store key') @@ -182,7 +184,7 @@ class SqliteStoreTests(unittest.TestCase): self.assertEqual(value, None) def test_5_set_replace(self): - with self.assertRaises(CSStoreError): + with self.assertRaises(CSStoreExists): self.store.set('key', 'replaced') self.store.set('key', 'replaced', replace=True) |