Skip to content

Commit

Permalink
fix: log error messages (#16935) (#16960)
Browse files Browse the repository at this point in the history
Log error messages and throw more
generic exceptions.

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
  • Loading branch information
vaadin-bot and caalador committed Jun 5, 2023
1 parent 9aba71c commit 1717a07
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 @@ -152,10 +153,12 @@ static void invokeMethod(Component instance, Class<?> clazz,
invokeMethod(compositeContent, compositeContent.getClass(),
methodName, args, promiseId, inert);
} else {
String msg = String.format("Neither class '%s' "
+ "nor its super classes declare event handler method '%s'",
instance.getClass().getName(), methodName);
throw new IllegalStateException(msg);
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(
"Faulty method invocation. See server log for more details.");
}
}

Expand All @@ -166,10 +169,12 @@ private static Optional<Method> findMethod(Component instance,
.filter(method -> hasMethodAnnotation(method))
.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 @@ -378,4 +383,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 1717a07

Please sign in to comment.