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:
parent
a774647c26
commit
c3155afc21
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user