It would be nice to include generic exceptions, else users can only conditionally use exceptions classes on the basis of their existence without any clear guidance outside of trying each manually, and will accumulate as multiple error handling styles in a codebase.
>>> import boto3
>>> client = boto3.client('s3')
>>> client.exceptions.AccessDenied
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kapilt/projects/cloud-custodian/lib/python3.6/site-packages/botocore/errorfactory.py", line 53, in __getattr__
self, name, ', '.join(exception_cls_names)))
AttributeError: <botocore.errorfactory.S3Exceptions object at 0x108f2efd0> object has no attribute 'AccessDenied'. Valid exceptions are: BucketAlreadyExists, BucketAlreadyOwnedByYou, NoSuchBucket, NoSuchKey, NoSuchUpload, ObjectAlreadyInActiveTierError, ObjectNotInActiveTierError
as an easy alternative, exposing error factory off the client and allowing users to create/retrieve exceptions by code would be nice.
something like
except client.exceptions.for_code('AccessDenied'):
pass
which would do a from_code for class cache lookup before constructing & caching.
Yeah I think something like that would be great! The downfall of what we have now is it is based off of the service models, which don't always define every exception. A solution like for_code would be cool.
Question, if AccessDenied is returned by S3, why isn't it part of the service definition?
Greetings! It looks like this issue hasn鈥檛 been active in longer than one year. We encourage you to check if this is still an issue in the latest release. Because it has been longer than one year since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment to prevent automatic closure, or if the issue is already closed, please feel free to reopen it.
Most helpful comment
something like
which would do a from_code for class cache lookup before constructing & caching.