Skip to content

Commit

Permalink
Document how 'NotFoundError' propagates.
Browse files Browse the repository at this point in the history
Describe suppressing it via 'bucket.delete_keys([key], on_error=lambda k:None'.

Fixes #160.
  • Loading branch information
tseaver committed Nov 3, 2014
1 parent f33e557 commit 16b581c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ def delete_key(self, key):
:rtype: :class:`gcloud.storage.key.Key`
:returns: The key that was just deleted.
:raises: :class:`gcloud.storage.exceptions.NotFoundError`
:raises: :class:`gcloud.storage.exceptions.NotFoundError` (to suppress
the exception, call ``delete_keys``, passing a no-op
``on_error`` callback, e.g.::
>>> bucket.delete_keys([key], on_error=lambda *key: pass)
"""
key = self.new_key(key)
self.connection.api_request(method='DELETE', path=key.path)
Expand All @@ -204,8 +208,12 @@ def delete_keys(self, keys, on_error=None):
:param keys: A list of key names or Key objects to delete.
:type on_error: a callable taking (key)
:param on_error: If not ``None``, called once for each key which
raises a ``NotFoundError``.
:param on_error: If not ``None``, called once for each key raising
:class:`gcloud.storage.exceptions.NotFoundError`;
otherwise, the exception is propagated.
:raises: :class:`gcloud.storage.exceptions.NotFoundError` (if
`on_error` is not passed).
"""
for key in keys:
try:
Expand Down
1 change: 1 addition & 0 deletions gcloud/storage/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def delete(self):
:rtype: :class:`Key`
:returns: The key that was just deleted.
:raises: :class:`gcloud.storage.exceptions.NotFoundError`.
"""
return self.bucket.delete_key(self)

Expand Down

0 comments on commit 16b581c

Please sign in to comment.