Skip to content

Conversation

@gautamomento
Copy link
Contributor

@gautamomento gautamomento commented Jan 29, 2022

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.
@gautamomento gautamomento requested review from rlinehan and removed request for rlinehan January 31, 2022 15:06
@gautamomento gautamomento marked this pull request as draft January 31, 2022 15:15
@gautamomento
Copy link
Contributor Author

@gautamomento gautamomento force-pushed the u/gautamomento/errorhandling branch from 5340927 to a718abc Compare February 1, 2022 16:00
Comment on lines 11 to 12
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')
Copy link
Contributor

@tylerburdsall tylerburdsall Feb 1, 2022

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. Thank you.

Copy link
Contributor Author

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.

@gautamomento gautamomento changed the title fix: Rename Error and tighten cache name validations fix: Handle GRPC Error Codes. Feb 1, 2022
Copy link
Contributor

@rlinehan rlinehan left a 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!

CreateCacheResponse
Raises:
InvalidInputError: If cache name is None.
Copy link
Contributor

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

Raises:
CacheNotFoundError: If an attempt is made to delete a MomentoCache that doesn't exits.
InvalidInputError: If cache name is None.
Copy link
Contributor

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.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CacheExistsError: If cache with the given name already exists.
AlreadyExistsError: If cache with the given name already exists.

DeleteCacheResponse
Raises:
CacheNotFoundError: If an attempt is made to delete a MomentoCache that doesn't exits.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

grpc.StatusCode.ALREADY_EXISTS: errors.CacheExistsError,
grpc.StatusCode.INVALID_ARGUMENT: errors.CacheValueError,
grpc.StatusCode.NOT_FOUND: errors.CacheNotFoundError,
grpc.StatusCode.INVALID_ARGUMENT: errors.BadRequestError,
Copy link
Contributor

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?

Copy link
Contributor Author

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*

gautamomento and others added 5 commits February 1, 2022 11:53
rlinehan
rlinehan previously approved these changes Feb 1, 2022
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')
Copy link
Contributor

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.

tylerburdsall
tylerburdsall previously approved these changes Feb 1, 2022
Co-authored-by: Ruth Linehan <1530016+rlinehan@users.noreply.github.com>
@gautamomento gautamomento dismissed stale reviews from tylerburdsall and rlinehan via 09a4f68 February 1, 2022 21:28
rlinehan
rlinehan previously approved these changes Feb 1, 2022
Copy link
Contributor

@rlinehan rlinehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@gautamomento gautamomento merged commit 8f68a1f into main Feb 1, 2022
@gautamomento gautamomento deleted the u/gautamomento/errorhandling branch February 1, 2022 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle grpc status codes (e.g. RESOURCE_EXHAUSTED) Errors for invalid input are inconsistent CacheValueError name is confusing

5 participants