Skip to content
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

Streamline creation of GRPC Exceptions #2502

Open
daschl opened this issue Feb 7, 2023 · 1 comment
Open

Streamline creation of GRPC Exceptions #2502

daschl opened this issue Feb 7, 2023 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@daschl
Copy link
Contributor

daschl commented Feb 7, 2023

At the moment, a GRPC exception can be created as

// Without Description
throw new GrpcStatusException(GrpcStatusCode.PERMISSION_DENIED.status());

// With Description
throw new GrpcStatusException(new GrpcStatus(GrpcStatusCode.PERMISSION_DENIED, "my-description"));

Other GRPC implementations provide convenience methods like:

throw PERMISSION_DENIED.withDescription("denied!").asException();

We could potentially add something similar to streamline exception generation (also including withCause, etc).

@daschl daschl added enhancement New feature or request good first issue Good for newcomers labels Feb 7, 2023
cmwigard added a commit to cmwigard/servicetalk that referenced this issue May 1, 2023
…hods.

Motivation:

In reference to issue apple#2502, there should be a more convenient way to initialize GRPC Exceptions analogous to other GRPC implementations.

Modifications:

- Removed the deprecation from GrpcStatus.asException as it is required for this implementation of desired functionality.
- Added additional constructor for GrpcStatus to support initialization from codeValue and description.
- Added convenience method GrpcStatusCode.withDescription to support desired functionality.
- Added GrpcStatusTest.testGrpcStatusExceptionFromGrpcStatusCode for test-driven development and better test coverage.

Result:

GRPC Exceptions can now be initialized and thrown more conveniently.

What is the result of this change?
@cmwigard
Copy link

cmwigard commented May 1, 2023

I had a go at this issue as my first contribution to ServiceTalk, I hope you don't mind.
Let me know if there is anything you would like me to change or discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants