rmetzger commented on a change in pull request #11536: [FLINK-16807][e2e] Improve reporting for instantiation errors URL: https://github.com/apache/flink/pull/11536#discussion_r400955480
########## File path: flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/util/FactoryUtils.java ########## @@ -43,24 +45,43 @@ * @throws RuntimeException if no or multiple resources could be instantiated * @return created instance */ - public static <R, F> R loadAndInvokeFactory(final Class<F> factoryInterface, final Function<F, Optional<R>> factoryInvoker, final Supplier<F> defaultProvider) { + public static <R, F> R loadAndInvokeFactory(final Class<F> factoryInterface, final FactoryInvoker<F, R> factoryInvoker, final Supplier<F> defaultProvider) { final ServiceLoader<F> factories = ServiceLoader.load(factoryInterface); - final List<R> resources = StreamSupport.stream(factories.spliterator(), false) - .map(factoryInvoker) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); + final List<R> instantiatedResources = new ArrayList<>(); + final List<Exception> errorsDuringInitialization = new ArrayList<>(); + for (F factory : factories) { + try { + R resource = factoryInvoker.invoke(factory); + instantiatedResources.add(resource); + LOG.info("Instantiated {}.", resource.getClass().getSimpleName()); + } catch (Exception e) { + LOG.debug("Factory {} could not instantiate instance.", factory.getClass().getSimpleName(), e); + errorsDuringInitialization.add(e); + } + } - if (resources.size() == 1) { - return resources.get(0); + if (instantiatedResources.size() == 1) { + return instantiatedResources.get(0); } - if (resources.isEmpty()) { - return factoryInvoker.apply(defaultProvider.get()) - .orElseThrow(() -> new RuntimeException("Could not instantiate instance using default factory.")); + if (instantiatedResources.isEmpty()) { + try { + return factoryInvoker.invoke(defaultProvider.get()); + } catch (Exception e) { + final RuntimeException exception = new RuntimeException("Could not instantiate instance."); Review comment: Thanks a lot! I can confirm that the error reporting is much better now!- ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services