Rethrow KeyError as DoesNotExistError in urlmarks.

From @TheCompiler:
To expand on this: I think it's fine to use KeyError on a lower level, i.e.
with the SqlTable object with a dict-like interface. However, on this higher
level, I think it makes sense to re-raise them as more specific exceptions.
This commit is contained in:
Ryan Roden-Corrent 2017-02-12 08:53:50 -05:00
parent a774647c26
commit c3155afc21
2 changed files with 12 additions and 3 deletions

View File

@ -1261,7 +1261,7 @@ class CommandDispatcher:
url = self._current_url()
try:
quickmark_manager.delete_by_qurl(url)
except KeyError as e:
except urlmarks.DoesNotExistError as e:
raise cmdexc.CommandError(str(e))
else:
try:

View File

@ -53,6 +53,13 @@ class InvalidUrlError(Error):
pass
class DoesNotExistError(Error):
"""Exception emitted when a given URL does not exist."""
pass
class AlreadyExistsError(Error):
"""Exception emitted when a given URL does already exist."""
@ -179,12 +186,14 @@ class QuickmarkManager(UrlMarkManager):
try:
self.delete(urlstr, field='url')
except KeyError:
raise KeyError("Quickmark for '{}' not found!".format(urlstr))
raise DoesNotExistError("Quickmark for '{}' not found!"
.format(urlstr))
def get(self, name):
"""Get the URL of the quickmark named name as a QUrl."""
if name not in self:
raise KeyError("Quickmark '{}' does not exist!".format(name))
raise DoesNotExistError("Quickmark '{}' does not exist!"
.format(name))
urlstr = self[name]
try:
url = urlutils.fuzzy_url(urlstr, do_search=False)