Skip to content

Commit

Permalink
fix: log error messages (#16935) (CP: 2.9) (#16963)
Browse files Browse the repository at this point in the history
Log error messages and throw more
generic exceptions.
  • Loading branch information
caalador authored Jun 5, 2023
1 parent 03f0347 commit 1814087
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vaadin.flow.component.ClientCallable;
Expand Down Expand Up @@ -142,11 +143,12 @@ static void invokeMethod(Component instance, Class<?> clazz,
invokeMethod(compositeContent, compositeContent.getClass(),
methodName, args, promiseId);
} else {
String msg = String.format(
"Neither class '%s' "
getLogger().error(String.format(
"Faulty method invocation. Neither class '%s' "
+ "nor its super classes declare event handler method '%s'",
instance.getClass().getName(), methodName);
throw new IllegalStateException(msg);
instance.getClass().getName(), methodName));
throw new IllegalStateException(
"Faulty method invocation. See server log for more details.");
}
}

Expand All @@ -158,11 +160,12 @@ private static Optional<Method> findMethod(Component instance,
|| method.isAnnotationPresent(ClientCallable.class))
.collect(Collectors.toList());
if (methods.size() > 1) {
String msg = String.format(
"Class '%s' contains "
+ "several event handler method with the same name '%s'",
instance.getClass().getName(), methodName);
throw new IllegalStateException(msg);
getLogger().error(String.format(
"Method conflict in event handler. Class '%s' contains "
+ "several event handler methods with the same name '%s'",
instance.getClass().getName(), methodName));
throw new IllegalStateException(
"Method conflict in event handler with multiple methods with same name. See server log for more details.");
} else if (methods.size() == 1) {
return Optional.of(methods.get(0));
} else if (!Component.class.equals(clazz)) {
Expand Down Expand Up @@ -372,4 +375,9 @@ private static Collection<RpcDecoder> loadDecoders() {
decoders.add(new DefaultRpcDecoder());
return decoders;
}

private static Logger getLogger() {
return LoggerFactory.getLogger(
PublishedServerEventHandlerRpcHandler.class.getName());
}
}

0 comments on commit 1814087

Please # to comment.