Skip to content

Commit

Permalink
v2.6: Add errors.ALL
Browse files Browse the repository at this point in the history
  • Loading branch information
benkehoe committed Nov 2, 2022
1 parent 7095cc8 commit 3f5154f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

`aws-error-utils` uses [monotonic versioning](blog.appliedcompscilab.com/monotonic_versioning_manifesto/).

## v2.6
* Add `errors.ALL` to match all `ClientError`s.

## v2.5
* Fix type annotations.

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ s3 = boto3.client('s3')
try:
s3.get_object(Bucket='my-bucket', Key='example')
except errors.NoSuchBucket as error:
# or
# except catch_aws_error('NoSuchBucket') as error:
print(error.message)
# error handling
```
Expand Down Expand Up @@ -115,6 +117,8 @@ except (errors.NoSuchBucket, errors.NoSuchKey) as error:
# error handling
```

You can catch all `ClientError`s with `errors.ALL`.

You can only use this style for error codes that work as Python property names.
For error codes like EC2's `InvalidInstanceID.NotFound`, you have to use `catch_aws_error()` (see below).

Expand Down
4 changes: 3 additions & 1 deletion aws_error_utils/aws_error_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
operation_name = e.operation_name
"""

__version__ = "2.5.0" # update here and pyproject.toml
__version__ = "2.6.0" # update here and pyproject.toml

__all__ = [
"AWSErrorInfo",
Expand Down Expand Up @@ -187,6 +187,8 @@ def __getattr__(self, name) -> Type[BaseException]:
self.__name__, name
)
)
if name in ["ALL", "ALL_CODES"]:
name = ALL_CODES
return catch_aws_error(name)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aws-error-utils"
version = "2.5.0" # update here and aws_error_utils.py
version = "2.6.0" # update here and aws_error_utils.py
description = "Error-handling functions for boto3/botocore"
authors = ["Ben Kehoe"]
license = "Apache-2.0"
Expand Down
16 changes: 16 additions & 0 deletions test_aws_error_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ def test_errors():
with pytest.raises(RuntimeError):
errors()

try:
raise error
except errors.ALL as e:
pass
except Exception:
assert False

class OtherError(Exception):
pass

try:
raise OtherError("test")
except errors.ALL as e:
assert False
except OtherError:
assert True

def test_make_aws_error():
args = {
Expand Down

0 comments on commit 3f5154f

Please sign in to comment.