Skip to content

Commit 93af2ba

Browse files
authored
Merge pull request quarkusio#47513 from Postremus/issues/38562-no-param-log-message
Exceptions thrown by resteasy reactive itself do not need to be wrapped
2 parents 31ba82e + 62e684d commit 93af2ba

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.quarkus.rest.client.reactive;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.net.URI;
6+
7+
import jakarta.ws.rs.GET;
8+
import jakarta.ws.rs.Path;
9+
10+
import org.junit.jupiter.api.Assertions;
11+
import org.junit.jupiter.api.Test;
12+
import org.junit.jupiter.api.extension.RegisterExtension;
13+
14+
import io.quarkus.test.QuarkusUnitTest;
15+
16+
class ClientMultipleBodyParamLogMessageTest {
17+
@RegisterExtension
18+
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
19+
.withApplicationRoot((jar) -> jar
20+
.addClass(Client.class));
21+
22+
@Test
23+
void basicTest() {
24+
try {
25+
QuarkusRestClientBuilder.newBuilder().baseUri(URI.create("http://localhost:8081"))
26+
.build(Client.class);
27+
} catch (Exception e) {
28+
assertThat(e.getMessage()).endsWith(
29+
"Failed to generate client for class interface io.quarkus.rest.client.reactive.ClientMultipleBodyParamLogMessageTest$Client : Resource method 'io.quarkus.rest.client.reactive.ClientMultipleBodyParamLogMessageTest$Client#java.lang.String getMessagesForTopic(int param1, int param2)' can only have a single body parameter, but has at least 2. A body parameter is a method parameter without any annotations. Last discovered body parameter is 'param2'.");
30+
return;
31+
}
32+
Assertions.fail("Should have thrown an exception");
33+
}
34+
35+
public interface Client {
36+
@GET
37+
@Path("/messages")
38+
String getMessagesForTopic(int param1, int param2);
39+
}
40+
}

independent-projects/resteasy-reactive/client/processor/src/main/java/org/jboss/resteasy/reactive/client/processor/scanning/ClientEndpointIndexer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private MethodParameter parseClientBeanParam(ClassInfo beanParamClassInfo, Index
142142
protected InjectableBean scanInjectableBean(ClassInfo currentClassInfo, ClassInfo actualEndpointInfo,
143143
Map<String, String> existingConverters, AdditionalReaders additionalReaders,
144144
Map<String, InjectableBean> injectableBeans, boolean hasRuntimeConverters) {
145-
throw new RuntimeException("Injectable beans not supported in client");
145+
throw new RuntimeException("Injectable beans are not supported in client");
146146
}
147147

148148
@Override

independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/EndpointIndexer.java

+17-12
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,12 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf
641641
String defaultValue = parameterResult.getDefaultValue();
642642
ParameterType type = parameterResult.getType();
643643
if (type == ParameterType.BODY) {
644-
if (bodyParamType != null)
645-
throw new RuntimeException(String.format(
646-
"Resource method '%s#%s' can only have a single body parameter: '%s'",
644+
if (bodyParamType != null) {
645+
throw new DeploymentException(String.format(
646+
"Resource method '%s#%s' can only have a single body parameter, but has at least 2. A body parameter is a method parameter without any annotations. Last discovered body parameter is '%s'.",
647647
currentMethodInfo.declaringClass().name(), currentMethodInfo,
648648
currentMethodInfo.parameterName(i)));
649+
}
649650
bodyParamType = paramType;
650651
if (GET.equals(httpMethod) || HEAD.equals(httpMethod) || OPTIONS.equals(httpMethod)) {
651652
warnAboutMissUsedBodyParameter(httpMethod, currentMethodInfo);
@@ -673,7 +674,7 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf
673674
if (bodyParamType != null
674675
&& !bodyParamType.name().equals(ResteasyReactiveDotNames.MULTI_VALUED_MAP)
675676
&& !bodyParamType.name().equals(ResteasyReactiveDotNames.STRING)) {
676-
throw new RuntimeException(String.format(
677+
throw new DeploymentException(String.format(
677678
"'@FormParam' and '@RestForm' cannot be used in a resource method that contains a body parameter. Offending method is "
678679
+ "'%s#%s'",
679680
currentMethodInfo.declaringClass().name(), currentMethodInfo));
@@ -689,7 +690,7 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf
689690
}
690691
// TODO: does it make sense to default to MediaType.MULTIPART_FORM_DATA when no consumes is set?
691692
if (!validConsumes) {
692-
throw new RuntimeException(String.format(
693+
throw new DeploymentException(String.format(
693694
"'@FormParam' and '@RestForm' can only be used on methods annotated with '@Consumes(MediaType.MULTIPART_FORM_DATA)' '@Consumes(MediaType.APPLICATION_FORM_URLENCODED)'. Offending method is "
694695
+ "'%s#%s'",
695696
currentMethodInfo.declaringClass().name(), currentMethodInfo));
@@ -811,9 +812,11 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf
811812
method));
812813
}
813814
return method;
814-
} catch (Exception e) {
815-
throw new RuntimeException(String.format("Failed to process method '%s#%s'",
816-
currentMethodInfo.declaringClass().name(), currentMethodInfo), e);
815+
} catch (DeploymentException e) {
816+
throw e;
817+
} catch (RuntimeException e) {
818+
throw new RuntimeException(String.format("Failed to process method '%s#%s'. Reason: %s",
819+
currentMethodInfo.declaringClass().name(), currentMethodInfo, e.getMessage()), e);
817820
}
818821
}
819822

@@ -1288,9 +1291,9 @@ public PARAM extractParameterInfo(ClassInfo currentClassInfo, ClassInfo actualEn
12881291
return builder;
12891292
} else if (moreThanOne(pathParam, queryParam, headerParam, formParam, cookieParam, contextParam, beanParam,
12901293
restPathParam, restQueryParam, restHeaderParam, restFormParam, restCookieParam)) {
1291-
throw new RuntimeException(
1294+
throw new DeploymentException(
12921295
"Cannot have more than one of @PathParam, @QueryParam, @HeaderParam, @FormParam, @CookieParam, @BeanParam, @Context on "
1293-
+ errorLocation);
1296+
+ builder.getErrorLocation());
12941297
} else if (pathParam != null) {
12951298
builder.setName(pathParam.value().asString());
12961299
builder.setType(ParameterType.PATH);
@@ -1513,10 +1516,12 @@ && isParameterContainerType(paramType.asClassType())) {
15131516
}
15141517
}
15151518
if (suspendedAnnotation != null && !elementType.equals(AsyncResponse.class.getName())) {
1516-
throw new RuntimeException("Can only inject AsyncResponse on methods marked @Suspended");
1519+
throw new DeploymentException(
1520+
"Can only inject AsyncResponse on methods marked @Suspended on " + builder.getErrorLocation());
15171521
}
15181522
if (builder.isSingle() && builder.getSeparator() != null) {
1519-
throw new DeploymentException("Single parameters should not be marked with @Separator");
1523+
throw new DeploymentException(
1524+
"Single parameters should not be marked with @Separator on " + builder.getErrorLocation());
15201525
}
15211526
builder.setElementType(elementType);
15221527
return builder;

0 commit comments

Comments
 (0)