Skip to content

feat: have DatastoreException extend BaseHttpServiceException, convert gRPC status codes to existing Datastore codes #1409

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

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

kolea2
Copy link
Contributor

@kolea2 kolea2 commented Apr 25, 2024

Building on top of changes in #1400, this PR reverts the updates in #1244 and instead translates gRPC error codes into existing Datastore ones.

This follows the same logic and patterns as in java-storage: https://github.com/googleapis/java-storage/blob/main/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcToHttpStatusCodeTranslation.java

…t gRPC status codes to existing Datastore codes
@kolea2 kolea2 requested review from a team as code owners April 25, 2024 14:38
@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Apr 25, 2024
@kolea2 kolea2 requested a review from BenWhitehead April 25, 2024 14:38
@product-auto-label product-auto-label bot added the api: datastore Issues related to the googleapis/java-datastore API. label Apr 25, 2024
@kolea2 kolea2 added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
@kolea2 kolea2 requested a review from a team as a code owner April 25, 2024 15:46
Copy link
Collaborator

@BenWhitehead BenWhitehead left a comment

Choose a reason for hiding this comment

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

A couple minor things, that may not need to be addressed in this PR (or at all)

GrpcToDatastoreCodeTranslation.grpcCodeToDatastoreStatusCode(gsc.getTransportCode());
}

// If there is a gRPC exception in our cause change pull it's error message up to be our
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// If there is a gRPC exception in our cause change pull it's error message up to be our
// If there is a gRPC exception in our cause, pull it's error message up to be our

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in subsequent commit.

@@ -1316,6 +1319,12 @@ public void testUpdate() {
datastore.delete(ENTITY3.getKey());
}

private void assertDatastoreException(
DatastoreException expected, String reason, int datastoreStatusCode) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this naming feels backward to me. I interpret expected as the value that is expected to hold in the assertion, not the exception that was expected to be thrown.

May not be worth the hassell, but I prefer the following pattern for asserting exceptions that are expected to be thrown:

DatastoreException datastoreException = org.junit.Assert.assertThrows(DatastoreException.class, () -> datastore.update(ENTITY3));
com.google.common.truth.Truth.assertThat(datastoreException.getReason()).isEqualTo(NOT_FOUND.name());
com.google.common.truth.Truth.assertThat(datastoreException.getCode()).isEqualTo(5);

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 like it! I've made these updates.

@kolea2 kolea2 added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
@kolea2 kolea2 merged commit 4c2d4ce into googleapis:V3-experimental Apr 25, 2024
18 checks passed
@kolea2 kolea2 deleted the http-errors branch April 25, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/java-datastore API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants