diff --git a/servicetalk-client-api/src/main/java/io/servicetalk/client/api/ConnectionFactory.java b/servicetalk-client-api/src/main/java/io/servicetalk/client/api/ConnectionFactory.java index 051f2d5133..552762a054 100644 --- a/servicetalk-client-api/src/main/java/io/servicetalk/client/api/ConnectionFactory.java +++ b/servicetalk-client-api/src/main/java/io/servicetalk/client/api/ConnectionFactory.java @@ -24,6 +24,7 @@ import javax.annotation.Nullable; import static io.servicetalk.client.api.DeprecatedToNewConnectionFactoryFilter.CONNECTION_FACTORY_CONTEXT_MAP_KEY; +import static io.servicetalk.concurrent.api.Single.failed; /** * A factory for creating new connections. @@ -46,8 +47,9 @@ public interface ConnectionFactory newConnection(ResolvedAddress address, @Nullable TransportObserver observer) { - throw new UnsupportedOperationException("ConnectionFactory#newConnection(ResolvedAddress, TransportObserver) " + - "is not supported by " + getClass()); + return failed(new UnsupportedOperationException( + "ConnectionFactory#newConnection(ResolvedAddress, TransportObserver) is not supported by " + + getClass())); } /** diff --git a/servicetalk-client-api/src/main/java/io/servicetalk/client/api/LoadBalancer.java b/servicetalk-client-api/src/main/java/io/servicetalk/client/api/LoadBalancer.java index c353fbbfb6..bbf8b88fe8 100644 --- a/servicetalk-client-api/src/main/java/io/servicetalk/client/api/LoadBalancer.java +++ b/servicetalk-client-api/src/main/java/io/servicetalk/client/api/LoadBalancer.java @@ -25,6 +25,8 @@ import java.util.function.Predicate; import javax.annotation.Nullable; +import static io.servicetalk.concurrent.api.Single.failed; + /** * Given multiple {@link SocketAddress}es select the most desired {@link SocketAddress} to use. This is typically used * to determine which connection to issue a request to. @@ -48,8 +50,8 @@ public interface LoadBalancer extends Listenab */ @Deprecated default Single selectConnection(Predicate selector) { // FIXME: 0.43 - remove deprecated method - throw new UnsupportedOperationException("LoadBalancer#selectConnection(Predicate) is not supported by " + - getClass()); + return failed(new UnsupportedOperationException( + "LoadBalancer#selectConnection(Predicate) is not supported by " + getClass())); } /** diff --git a/servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Generator.java b/servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Generator.java index 581875d668..07419c2f2b 100644 --- a/servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Generator.java +++ b/servicetalk-grpc-protoc/src/main/java/io/servicetalk/grpc/protoc/Generator.java @@ -899,9 +899,11 @@ private TypeSpec.Builder addClientInterfaces(final State state, final TypeSpec.B .addJavadoc(JAVADOC_PARAM + metadata + " the metadata associated with this client call." + lineSeparator()); } - return b.addStatement("throw new UnsupportedOperationException(\"This method is not " + - "implemented by \" + getClass() + \". Consider migrating to an alternative " + - "method or implement this method if it's required temporarily.\")"); + return b.addStatement("return $T.failed(new UnsupportedOperationException(\"" + + "This method is not implemented by \" + getClass() + \". Consider migrating " + + "to an alternative method or implement this method if it's required " + + "temporarily.\"))", clientMetaData.methodProto.getServerStreaming() ? + Publisher : Single); })) .addMethod(newRpcMethodSpec(clientMetaData.methodProto, EnumSet.of(INTERFACE, CLIENT), printJavaDocs, (methodName, b) -> { @@ -1050,7 +1052,7 @@ private MethodSpec newRpcMethodSpec( private static MethodSpec newRpcMethodSpec( final ClassName inClass, final ClassName outClass, final String methodName, - final boolean clientSteaming, final boolean serverStreaming, + final boolean clientStreaming, final boolean serverStreaming, final EnumSet flags, final boolean printJavaDocs, final BiFunction methodBuilderCustomizer) { final MethodSpec.Builder methodSpecBuilder = methodBuilderCustomizer.apply(methodName, @@ -1059,7 +1061,7 @@ private static MethodSpec newRpcMethodSpec( final Modifier[] mods = flags.contains(INTERFACE) ? new Modifier[0] : new Modifier[]{FINAL}; if (flags.contains(BLOCKING)) { - if (clientSteaming) { + if (clientStreaming) { if (flags.contains(CLIENT)) { methodSpecBuilder.addParameter(ParameterizedTypeName.get(Types.Iterable, inClass), request, mods); if (printJavaDocs) { @@ -1116,7 +1118,7 @@ private static MethodSpec newRpcMethodSpec( "propagated to the peer.", GrpcStatusException); } } else { - if (clientSteaming) { + if (clientStreaming) { methodSpecBuilder.addParameter(ParameterizedTypeName.get(Publisher, inClass), request, mods); if (printJavaDocs) { methodSpecBuilder.addJavadoc(JAVADOC_PARAM + request +