-
Notifications
You must be signed in to change notification settings - Fork 7
fix: Handle GRPC Error Codes. #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix for #23 - CacheValueError is a confusing name for surfacing INVALID_ARGUMENT errors. It can be easily confused with something related to setting a value in Cache. Proposing `CacheValueError` is renamed to `InvalidArgumentError` Fix for #24 - Given the type-safety in python, customers can accidentally pass unsupported types. This results in a ClientSdkException when in fact it is an Invalid Input Error. We already type check our keys, values, ttl, so just adding one for cache name. Though it may be just wise to let the type errors pass through.
|
I will be waiting for conclusion on https://www.notion.so/momentohq/GRPC-Status-Code-Mapping-35f76a4abc634e26b1129a649e1b329d |
5340927 to
a718abc
Compare
| if cache_name is None or not isinstance(cache_name, str): | ||
| raise errors.InvalidArgumentError('Cache name must be a non-None value with `str` type') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: it's a little more Pythonic to check non-null via:
if not cache_name or not isistance(cache_name, str)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually ended up keeping this as not check blocks '' empty strings. That is fine but just breaks the internal decision that we only perform client SDK validations that can't be done on the server side.
rlinehan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few places where the doc strings need to be updated, but otherwise looks good!
src/momento/simple_cache_client.py
Outdated
| CreateCacheResponse | ||
| Raises: | ||
| InvalidInputError: If cache name is None. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be removed now
src/momento/simple_cache_client.py
Outdated
| Raises: | ||
| CacheNotFoundError: If an attempt is made to delete a MomentoCache that doesn't exits. | ||
| InvalidInputError: If cache name is None. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be removed now.
src/momento/simple_cache_client.py
Outdated
| ClientSdkError: For any SDK checks that fail. | ||
| CacheValueError: If provided cache_name is empty. | ||
| InvalidArgumentError: If provided cache_name is empty. | ||
| CacheExistsError: If cache with the given name already exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CacheExistsError: If cache with the given name already exists. | |
| AlreadyExistsError: If cache with the given name already exists. |
src/momento/simple_cache_client.py
Outdated
| DeleteCacheResponse | ||
| Raises: | ||
| CacheNotFoundError: If an attempt is made to delete a MomentoCache that doesn't exits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CacheNotFoundError: If an attempt is made to delete a MomentoCache that doesn't exits. | |
| NotFoundError: If an attempt is made to delete a MomentoCache that doesn't exits. |
…nt to check on SDK
| grpc.StatusCode.ALREADY_EXISTS: errors.CacheExistsError, | ||
| grpc.StatusCode.INVALID_ARGUMENT: errors.CacheValueError, | ||
| grpc.StatusCode.NOT_FOUND: errors.CacheNotFoundError, | ||
| grpc.StatusCode.INVALID_ARGUMENT: errors.BadRequestError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be errors.InvalidArgumentError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. These are the naming conventions we will be following
https://www.notion.so/momentohq/GRPC-Status-Code-Mapping-35f76a4abc634e26b1129a649e1b329d
The second column:
BadRequest*
For SDK client side checks we will be using
InvalidArgument*
Co-authored-by: Ruth Linehan <1530016+rlinehan@users.noreply.github.com>
| if cache_name is None: | ||
| raise errors.InvalidInputError('Cache Name cannot be None') | ||
| if cache_name is None or not isinstance(cache_name, str): | ||
| raise errors.InvalidArgumentError('Cache name must be a non-None value with `str` type') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a nitpick that you can feel free ignore - I feel like saying a non-None value with str type is redundant, since str is not None? So could just say must be a non-empty string.
Co-authored-by: Ruth Linehan <1530016+rlinehan@users.noreply.github.com>
09a4f68
…lient-sdk-python into u/gautamomento/errorhandling
rlinehan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
Fix for #23, #24 and #27
Based on https://www.notion.so/momentohq/GRPC-Status-Code-Mapping-35f76a4abc634e26b1129a649e1b329d