diff --git a/src/main/java/com/google/api/generator/engine/ast/TypeNode.java b/src/main/java/com/google/api/generator/engine/ast/TypeNode.java index aef8f15727..46403071e1 100644 --- a/src/main/java/com/google/api/generator/engine/ast/TypeNode.java +++ b/src/main/java/com/google/api/generator/engine/ast/TypeNode.java @@ -65,6 +65,9 @@ public enum TypeKind { public static final TypeNode SHORT_OBJECT = withReference(ConcreteReference.withClazz(Short.class)); + public static final TypeNode CLASS_OBJECT = + withReference(ConcreteReference.withClazz(Class.class)); + public static final TypeNode BYTESTRING = TypeNode.withReference(ConcreteReference.withClazz(ByteString.class)); diff --git a/src/main/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposer.java index efdff56e6a..d76ee0bc1c 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposer.java @@ -56,6 +56,7 @@ import java.util.List; import java.util.Map; import java.util.Queue; +import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Generated; @@ -484,13 +485,55 @@ private static Statement createHandleObjectStatement( } TypeNode exceptionType = TypeNode.withReference(ConcreteReference.withClazz(Exception.class)); + Expr actualResponseTypeString = + MethodInvocationExpr.builder() + .setExprReferenceExpr( + MethodInvocationExpr.builder() + .setExprReferenceExpr(localResponseVarExpr) + .setMethodName("getClass") + .build()) + .setMethodName("getName") + .setReturnType(TypeNode.STRING) + .build(); + Function typeToStrFn = + t -> + MethodInvocationExpr.builder() + .setExprReferenceExpr( + VariableExpr.builder() + .setStaticReferenceType(t) + .setVariable( + Variable.builder() + .setType(TypeNode.CLASS_OBJECT) + .setName("class") + .build()) + .build()) + .setMethodName("getName") + .setReturnType(TypeNode.STRING) + .build(); + Expr expectedResponseTypeOneString = typeToStrFn.apply(protoMethod.outputType()); + Expr expectedResponseTypeTwoString = typeToStrFn.apply(exceptionType); + Expr newExceptionExpr = NewObjectExpr.builder() .setType( TypeNode.withReference(ConcreteReference.withClazz(IllegalArgumentException.class))) .setArguments( - Arrays.asList( - ValueExpr.withValue(StringObjectValue.withValue("Unrecognized response type")))) + // Generates something like: + // String.format("Unrecognized response type %s, expected %s or %s", + // Operation.class.getName(), Exception.class.getName()); + MethodInvocationExpr.builder() + .setStaticReferenceType(TypeNode.STRING) + .setMethodName("format") + .setArguments( + ValueExpr.withValue( + StringObjectValue.withValue( + "Unrecognized response type %s for method " + + protoMethod.name() + + ", expected %s or %s")), + actualResponseTypeString, + expectedResponseTypeOneString, + expectedResponseTypeTwoString) + .build()) .build(); return IfStatement.builder() diff --git a/src/main/java/com/google/api/generator/gapic/composer/RetrySettingsComposer.java b/src/main/java/com/google/api/generator/gapic/composer/RetrySettingsComposer.java index 0118d43eb1..77253189d2 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/RetrySettingsComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/RetrySettingsComposer.java @@ -316,10 +316,7 @@ public static Expr createLroSettingsBuilderExpr( t -> VariableExpr.builder() .setVariable( - Variable.builder() - .setType(TypeNode.withReference(ConcreteReference.withClazz(Class.class))) - .setName("class") - .build()) + Variable.builder().setType(TypeNode.CLASS_OBJECT).setName("class").build()) .setStaticReferenceType(t) .build(); builderSettingsExpr = diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java index 0b27868b1c..3b3bd8cddb 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java @@ -1561,11 +1561,7 @@ private static List createRpcLroExceptionTestCatchBody( Expr testExpectedValueExpr = VariableExpr.builder() - .setVariable( - Variable.builder() - .setType(TypeNode.withReference(ConcreteReference.withClazz(Class.class))) - .setName("class") - .build()) + .setVariable(Variable.builder().setType(TypeNode.CLASS_OBJECT).setName("class").build()) .setStaticReferenceType(FIXED_TYPESTORE.get("InvalidArgumentException")) .build(); Expr getCauseExpr = diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java index 45317be985..2774b90c3e 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java @@ -999,11 +999,7 @@ private static List createDefaultHelperAndGetterMethods( .setArguments( VariableExpr.builder() .setVariable( - Variable.builder() - .setType( - TypeNode.withReference(ConcreteReference.withClazz(Class.class))) - .setName("class") - .build()) + Variable.builder().setType(TypeNode.CLASS_OBJECT).setName("class").build()) .setStaticReferenceType( typeStore.get(ClassNames.getServiceStubSettingsClassName(service))) .build()) diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/MockEchoImpl.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/MockEchoImpl.golden index 779c195f71..6d78ee2827 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/goldens/MockEchoImpl.golden +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/MockEchoImpl.golden @@ -53,7 +53,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Echo, expected %s or %s", + response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); } } @@ -67,7 +73,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Expand, expected %s or %s", + response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); } } @@ -84,7 +96,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Collect, expected %s or %s", + response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); } } @@ -114,7 +132,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Chat, expected %s or %s", + response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); } } @@ -145,7 +169,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ChatAgain, expected %s or %s", + response.getClass().getName(), + EchoResponse.class.getName(), + Exception.class.getName()))); } } @@ -173,7 +203,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method PagedExpand, expected %s or %s", + response.getClass().getName(), + PagedExpandResponse.class.getName(), + Exception.class.getName()))); } } @@ -188,7 +224,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SimplePagedExpand, expected %s or %s", + response.getClass().getName(), + PagedExpandResponse.class.getName(), + Exception.class.getName()))); } } @@ -202,7 +244,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Wait, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -216,7 +264,13 @@ public class MockEchoImpl extends EchoImplBase { } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Block, expected %s or %s", + response.getClass().getName(), + BlockResponse.class.getName(), + Exception.class.getName()))); } } } diff --git a/test/integration/goldens/asset/MockAssetServiceImpl.java b/test/integration/goldens/asset/MockAssetServiceImpl.java index 1ef582b272..46798d0326 100644 --- a/test/integration/goldens/asset/MockAssetServiceImpl.java +++ b/test/integration/goldens/asset/MockAssetServiceImpl.java @@ -71,7 +71,13 @@ public void exportAssets( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ExportAssets, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -87,7 +93,13 @@ public void batchGetAssetsHistory( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method BatchGetAssetsHistory, expected %s or %s", + response.getClass().getName(), + BatchGetAssetsHistoryResponse.class.getName(), + Exception.class.getName()))); } } @@ -101,7 +113,11 @@ public void createFeed(CreateFeedRequest request, StreamObserver responseO } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateFeed, expected %s or %s", + response.getClass().getName(), Feed.class.getName(), Exception.class.getName()))); } } @@ -115,7 +131,11 @@ public void getFeed(GetFeedRequest request, StreamObserver responseObserve } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetFeed, expected %s or %s", + response.getClass().getName(), Feed.class.getName(), Exception.class.getName()))); } } @@ -130,7 +150,13 @@ public void listFeeds( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListFeeds, expected %s or %s", + response.getClass().getName(), + ListFeedsResponse.class.getName(), + Exception.class.getName()))); } } @@ -144,7 +170,11 @@ public void updateFeed(UpdateFeedRequest request, StreamObserver responseO } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateFeed, expected %s or %s", + response.getClass().getName(), Feed.class.getName(), Exception.class.getName()))); } } @@ -158,7 +188,13 @@ public void deleteFeed(DeleteFeedRequest request, StreamObserver response } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteFeed, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); } } @@ -174,7 +210,13 @@ public void searchAllResources( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SearchAllResources, expected %s or %s", + response.getClass().getName(), + SearchAllResourcesResponse.class.getName(), + Exception.class.getName()))); } } @@ -190,7 +232,13 @@ public void searchAllIamPolicies( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SearchAllIamPolicies, expected %s or %s", + response.getClass().getName(), + SearchAllIamPoliciesResponse.class.getName(), + Exception.class.getName()))); } } } diff --git a/test/integration/goldens/credentials/MockIAMCredentialsImpl.java b/test/integration/goldens/credentials/MockIAMCredentialsImpl.java index 851402cad9..be2f309d7c 100644 --- a/test/integration/goldens/credentials/MockIAMCredentialsImpl.java +++ b/test/integration/goldens/credentials/MockIAMCredentialsImpl.java @@ -70,7 +70,13 @@ public void generateAccessToken( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GenerateAccessToken, expected %s or %s", + response.getClass().getName(), + GenerateAccessTokenResponse.class.getName(), + Exception.class.getName()))); } } @@ -85,7 +91,13 @@ public void generateIdToken( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GenerateIdToken, expected %s or %s", + response.getClass().getName(), + GenerateIdTokenResponse.class.getName(), + Exception.class.getName()))); } } @@ -99,7 +111,13 @@ public void signBlob(SignBlobRequest request, StreamObserver r } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SignBlob, expected %s or %s", + response.getClass().getName(), + SignBlobResponse.class.getName(), + Exception.class.getName()))); } } @@ -113,7 +131,13 @@ public void signJwt(SignJwtRequest request, StreamObserver resp } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SignJwt, expected %s or %s", + response.getClass().getName(), + SignJwtResponse.class.getName(), + Exception.class.getName()))); } } } diff --git a/test/integration/goldens/library/MockLibraryServiceImpl.java b/test/integration/goldens/library/MockLibraryServiceImpl.java index f9c59c9467..ff65534071 100644 --- a/test/integration/goldens/library/MockLibraryServiceImpl.java +++ b/test/integration/goldens/library/MockLibraryServiceImpl.java @@ -84,7 +84,13 @@ public void createShelf(CreateShelfRequest request, StreamObserver respon } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateShelf, expected %s or %s", + response.getClass().getName(), + Shelf.class.getName(), + Exception.class.getName()))); } } @@ -98,7 +104,13 @@ public void getShelf(GetShelfRequest request, StreamObserver responseObse } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetShelf, expected %s or %s", + response.getClass().getName(), + Shelf.class.getName(), + Exception.class.getName()))); } } @@ -113,7 +125,13 @@ public void listShelves( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListShelves, expected %s or %s", + response.getClass().getName(), + ListShelvesResponse.class.getName(), + Exception.class.getName()))); } } @@ -127,7 +145,13 @@ public void deleteShelf(DeleteShelfRequest request, StreamObserver respon } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteShelf, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); } } @@ -141,7 +165,13 @@ public void mergeShelves(MergeShelvesRequest request, StreamObserver resp } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method MergeShelves, expected %s or %s", + response.getClass().getName(), + Shelf.class.getName(), + Exception.class.getName()))); } } @@ -155,7 +185,11 @@ public void createBook(CreateBookRequest request, StreamObserver responseO } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateBook, expected %s or %s", + response.getClass().getName(), Book.class.getName(), Exception.class.getName()))); } } @@ -169,7 +203,11 @@ public void getBook(GetBookRequest request, StreamObserver responseObserve } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetBook, expected %s or %s", + response.getClass().getName(), Book.class.getName(), Exception.class.getName()))); } } @@ -184,7 +222,13 @@ public void listBooks( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListBooks, expected %s or %s", + response.getClass().getName(), + ListBooksResponse.class.getName(), + Exception.class.getName()))); } } @@ -198,7 +242,13 @@ public void deleteBook(DeleteBookRequest request, StreamObserver response } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteBook, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); } } @@ -212,7 +262,11 @@ public void updateBook(UpdateBookRequest request, StreamObserver responseO } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateBook, expected %s or %s", + response.getClass().getName(), Book.class.getName(), Exception.class.getName()))); } } @@ -226,7 +280,11 @@ public void moveBook(MoveBookRequest request, StreamObserver responseObser } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method MoveBook, expected %s or %s", + response.getClass().getName(), Book.class.getName(), Exception.class.getName()))); } } } diff --git a/test/integration/goldens/logging/MockConfigServiceV2Impl.java b/test/integration/goldens/logging/MockConfigServiceV2Impl.java index 53fcedc2f8..fdbf74ac4d 100644 --- a/test/integration/goldens/logging/MockConfigServiceV2Impl.java +++ b/test/integration/goldens/logging/MockConfigServiceV2Impl.java @@ -92,7 +92,13 @@ public void listBuckets( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListBuckets, expected %s or %s", + response.getClass().getName(), + ListBucketsResponse.class.getName(), + Exception.class.getName()))); } } @@ -106,7 +112,13 @@ public void getBucket(GetBucketRequest request, StreamObserver respon } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetBucket, expected %s or %s", + response.getClass().getName(), + LogBucket.class.getName(), + Exception.class.getName()))); } } @@ -121,7 +133,13 @@ public void updateBucket( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateBucket, expected %s or %s", + response.getClass().getName(), + LogBucket.class.getName(), + Exception.class.getName()))); } } @@ -136,7 +154,13 @@ public void listSinks( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListSinks, expected %s or %s", + response.getClass().getName(), + ListSinksResponse.class.getName(), + Exception.class.getName()))); } } @@ -150,7 +174,13 @@ public void getSink(GetSinkRequest request, StreamObserver responseObse } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetSink, expected %s or %s", + response.getClass().getName(), + LogSink.class.getName(), + Exception.class.getName()))); } } @@ -164,7 +194,13 @@ public void createSink(CreateSinkRequest request, StreamObserver respon } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateSink, expected %s or %s", + response.getClass().getName(), + LogSink.class.getName(), + Exception.class.getName()))); } } @@ -178,7 +214,13 @@ public void updateSink(UpdateSinkRequest request, StreamObserver respon } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateSink, expected %s or %s", + response.getClass().getName(), + LogSink.class.getName(), + Exception.class.getName()))); } } @@ -192,7 +234,13 @@ public void deleteSink(DeleteSinkRequest request, StreamObserver response } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteSink, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); } } @@ -207,7 +255,13 @@ public void listExclusions( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListExclusions, expected %s or %s", + response.getClass().getName(), + ListExclusionsResponse.class.getName(), + Exception.class.getName()))); } } @@ -222,7 +276,13 @@ public void getExclusion( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetExclusion, expected %s or %s", + response.getClass().getName(), + LogExclusion.class.getName(), + Exception.class.getName()))); } } @@ -237,7 +297,13 @@ public void createExclusion( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateExclusion, expected %s or %s", + response.getClass().getName(), + LogExclusion.class.getName(), + Exception.class.getName()))); } } @@ -252,7 +318,13 @@ public void updateExclusion( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateExclusion, expected %s or %s", + response.getClass().getName(), + LogExclusion.class.getName(), + Exception.class.getName()))); } } @@ -267,7 +339,13 @@ public void deleteExclusion( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteExclusion, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); } } @@ -282,7 +360,13 @@ public void getCmekSettings( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetCmekSettings, expected %s or %s", + response.getClass().getName(), + CmekSettings.class.getName(), + Exception.class.getName()))); } } @@ -297,7 +381,13 @@ public void updateCmekSettings( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateCmekSettings, expected %s or %s", + response.getClass().getName(), + CmekSettings.class.getName(), + Exception.class.getName()))); } } } diff --git a/test/integration/goldens/logging/MockLoggingServiceV2Impl.java b/test/integration/goldens/logging/MockLoggingServiceV2Impl.java index 1f65485c7a..ece59015b9 100644 --- a/test/integration/goldens/logging/MockLoggingServiceV2Impl.java +++ b/test/integration/goldens/logging/MockLoggingServiceV2Impl.java @@ -78,7 +78,13 @@ public void deleteLog(DeleteLogRequest request, StreamObserver responseOb } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteLog, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); } } @@ -93,7 +99,13 @@ public void writeLogEntries( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method WriteLogEntries, expected %s or %s", + response.getClass().getName(), + WriteLogEntriesResponse.class.getName(), + Exception.class.getName()))); } } @@ -108,7 +120,13 @@ public void listLogEntries( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListLogEntries, expected %s or %s", + response.getClass().getName(), + ListLogEntriesResponse.class.getName(), + Exception.class.getName()))); } } @@ -124,7 +142,13 @@ public void listMonitoredResourceDescriptors( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListMonitoredResourceDescriptors, expected %s or %s", + response.getClass().getName(), + ListMonitoredResourceDescriptorsResponse.class.getName(), + Exception.class.getName()))); } } @@ -138,7 +162,13 @@ public void listLogs(ListLogsRequest request, StreamObserver r } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListLogs, expected %s or %s", + response.getClass().getName(), + ListLogsResponse.class.getName(), + Exception.class.getName()))); } } } diff --git a/test/integration/goldens/logging/MockMetricsServiceV2Impl.java b/test/integration/goldens/logging/MockMetricsServiceV2Impl.java index 4938e889ae..64855c0a62 100644 --- a/test/integration/goldens/logging/MockMetricsServiceV2Impl.java +++ b/test/integration/goldens/logging/MockMetricsServiceV2Impl.java @@ -77,7 +77,13 @@ public void listLogMetrics( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListLogMetrics, expected %s or %s", + response.getClass().getName(), + ListLogMetricsResponse.class.getName(), + Exception.class.getName()))); } } @@ -92,7 +98,13 @@ public void getLogMetric( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetLogMetric, expected %s or %s", + response.getClass().getName(), + LogMetric.class.getName(), + Exception.class.getName()))); } } @@ -107,7 +119,13 @@ public void createLogMetric( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateLogMetric, expected %s or %s", + response.getClass().getName(), + LogMetric.class.getName(), + Exception.class.getName()))); } } @@ -122,7 +140,13 @@ public void updateLogMetric( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateLogMetric, expected %s or %s", + response.getClass().getName(), + LogMetric.class.getName(), + Exception.class.getName()))); } } @@ -137,7 +161,13 @@ public void deleteLogMetric( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteLogMetric, expected %s or %s", + response.getClass().getName(), + Empty.class.getName(), + Exception.class.getName()))); } } } diff --git a/test/integration/goldens/redis/MockCloudRedisImpl.java b/test/integration/goldens/redis/MockCloudRedisImpl.java index 953045dea1..bc4e3d8d7d 100644 --- a/test/integration/goldens/redis/MockCloudRedisImpl.java +++ b/test/integration/goldens/redis/MockCloudRedisImpl.java @@ -70,7 +70,13 @@ public void listInstances( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListInstances, expected %s or %s", + response.getClass().getName(), + ListInstancesResponse.class.getName(), + Exception.class.getName()))); } } @@ -84,7 +90,13 @@ public void getInstance(GetInstanceRequest request, StreamObserver res } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetInstance, expected %s or %s", + response.getClass().getName(), + Instance.class.getName(), + Exception.class.getName()))); } } @@ -99,7 +111,13 @@ public void createInstance( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method CreateInstance, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -114,7 +132,13 @@ public void updateInstance( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpdateInstance, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -129,7 +153,13 @@ public void upgradeInstance( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method UpgradeInstance, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -144,7 +174,13 @@ public void importInstance( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ImportInstance, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -159,7 +195,13 @@ public void exportInstance( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ExportInstance, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -174,7 +216,13 @@ public void failoverInstance( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method FailoverInstance, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } @@ -189,7 +237,13 @@ public void deleteInstance( } else if (response instanceof Exception) { responseObserver.onError(((Exception) response)); } else { - responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method DeleteInstance, expected %s or %s", + response.getClass().getName(), + Operation.class.getName(), + Exception.class.getName()))); } } }