Skip to content

Commit

Permalink
thrown DatabaseNotFoundError exception if document is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jaedsonpys committed Jan 2, 2023
1 parent 6acff98 commit c915a28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cookiedb/_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_document(self, database: str) -> Union[None, dict]:
with open(document_path, 'rb') as reader:
data = secpickle.load(reader, self._key)
except FileNotFoundError:
document = None
raise exceptions.DatabaseNotFoundError(f'Database "{database}" not found')
except sp_exceptions.IntegrityUnconfirmedError:
raise exceptions.InvalidDatabaseKeyError(f'Invalid key to "{database}" database')
else:
Expand Down
7 changes: 6 additions & 1 deletion cookiedb/cookiedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ class instance.
raise exceptions.DatabaseExistsError(f'Database {database_name} already exists.')

def _get_database_items(self):
database = self._document.get_document(self._open_database)
try:
database = self._document.get_document(self._open_database)
except exceptions.DatabaseNotFoundError:
self._open_database = None
raise exceptions.DatabaseNotFoundError

return database.get('items')

def _filter_path_list(self, path_list: list) -> str:
Expand Down

0 comments on commit c915a28

Please sign in to comment.