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

Default methods that return async sources should not throw #2288

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -46,8 +47,9 @@ public interface ConnectionFactory<ResolvedAddress, C extends ListenableAsyncClo
*/
@Deprecated // FIXME: 0.43 - remove deprecated method
default Single<C> 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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -48,8 +50,8 @@ public interface LoadBalancer<C extends LoadBalancedConnection> extends Listenab
*/
@Deprecated
default Single<C> selectConnection(Predicate<C> 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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {
Expand Down Expand Up @@ -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<NewRpcMethodFlag> flags, final boolean printJavaDocs,
final BiFunction<String, MethodSpec.Builder, MethodSpec.Builder> methodBuilderCustomizer) {
final MethodSpec.Builder methodSpecBuilder = methodBuilderCustomizer.apply(methodName,
Expand All @@ -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) {
Expand Down Expand Up @@ -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 +
Expand Down