From c52cce5514adbec08fe0d26ffd3172a27bce4ba4 Mon Sep 17 00:00:00 2001 From: peubouzon Date: Sun, 28 Jul 2024 21:03:32 -0300 Subject: [PATCH 1/4] Improve message when multiple search extensions are found --- .../boot/AmbiguousSearchExtensionTest.java | 68 +++++++++++++++++++ .../runtime/bean/HibernateSearchBeanUtil.java | 14 ++-- 2 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java diff --git a/extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java b/extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java new file mode 100644 index 0000000000000..de35daca8c3d3 --- /dev/null +++ b/extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java @@ -0,0 +1,68 @@ +package io.quarkus.hibernate.search.standalone.elasticsearch.test.boot; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hibernate.search.engine.reporting.EntityIndexingFailureContext; +import org.hibernate.search.engine.reporting.FailureContext; +import org.hibernate.search.engine.reporting.FailureHandler; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.SearchEntity; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.search.standalone.elasticsearch.SearchExtension; +import io.quarkus.test.QuarkusUnitTest; + +public class AmbiguousSearchExtensionTest { + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClass(MyEntity.class) + .addClass(SearchFailureHandler.class) + .addClass(AnotherSearchFailureHandler.class) + .addAsResource("application.properties")) + .assertException(throwable -> assertThat(throwable) + .hasNoSuppressedExceptions() + .rootCause() + .hasMessageContainingAll("Multiple instances of FailureHandler were found at ", + "io.quarkus.hibernate.search.standalone.elasticsearch.test.boot.AmbiguousSearchExtensionTest.SearchFailureHandler", + "io.quarkus.hibernate.search.standalone.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler", + "for Hibernate Search Standalone. At most one instance can be assigned.")); + + @SearchEntity + @Indexed + public static class MyEntity { + @DocumentId + private Long id; + } + + @SearchExtension + public static class SearchFailureHandler implements FailureHandler { + @Override + public void handle(FailureContext failureContext) { + } + + @Override + public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { + } + } + + @SearchExtension + public static class AnotherSearchFailureHandler implements FailureHandler { + @Override + public void handle(FailureContext failureContext) { + } + + @Override + public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { + } + } + + @Test + public void test() { + Assertions.fail("Startup should have failed"); + } + +} diff --git a/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java b/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java index 21cfe3137c809..b10d32265a511 100644 --- a/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java +++ b/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java @@ -28,21 +28,23 @@ private static Optional> singleExtensionBeanReferenceFor(Cl String backendName, String indexName) { InjectableInstance instance = extensionInstanceFor(beanType, backendName, indexName); if (instance.isAmbiguous()) { + List ambiguousClassNames = instance.handlesStream().map(h -> h.getBean().getBeanClass().getCanonicalName()) + .toList(); if (indexName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found for Hibernate Search Standalone index %2$s." + "Multiple instances of %1$s were found at %2$s for Hibernate Search Standalone index %3$s." + " At most one instance can be assigned to each index.", - beanType.getSimpleName(), indexName)); + beanType.getSimpleName(), ambiguousClassNames, indexName)); } else if (backendName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found for Hibernate Search Standalone backend %2$s." + "Multiple instances of %1$s were found at %2$s for Hibernate Search Standalone backend %3$s." + " At most one instance can be assigned to each backend.", - beanType.getSimpleName(), backendName)); + beanType.getSimpleName(), ambiguousClassNames, backendName)); } else { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found for Hibernate Search Standalone." + "Multiple instances of %1$s were found at %2$s for Hibernate Search Standalone." + " At most one instance can be assigned.", - beanType.getSimpleName())); + beanType.getSimpleName(), ambiguousClassNames)); } } return instance.isResolvable() ? Optional.of(new ArcBeanReference<>(instance.getHandle().getBean())) : Optional.empty(); From 48d4ace83b16d3a6f8556b75f0cb1312e5e2a4f7 Mon Sep 17 00:00:00 2001 From: peubouzon Date: Sun, 28 Jul 2024 21:13:11 -0300 Subject: [PATCH 2/4] Improve message when multiple search extensions are found --- .../boot/AmbiguousSearchExtensionTest.java | 72 +++++++++++++++++++ .../runtime/bean/HibernateSearchBeanUtil.java | 14 ++-- 2 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java new file mode 100644 index 0000000000000..b0942ad6484d8 --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java @@ -0,0 +1,72 @@ +package io.quarkus.hibernate.search.orm.elasticsearch.test.boot; + +import static org.assertj.core.api.Assertions.assertThat; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; + +import org.hibernate.search.engine.reporting.EntityIndexingFailureContext; +import org.hibernate.search.engine.reporting.FailureContext; +import org.hibernate.search.engine.reporting.FailureHandler; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.search.orm.elasticsearch.SearchExtension; +import io.quarkus.test.QuarkusUnitTest; + +public class AmbiguousSearchExtensionTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClass(MyEntity.class) + .addClass(SearchFailureHandler.class) + .addClass(AnotherSearchFailureHandler.class) + .addAsResource("application.properties")) + .assertException(throwable -> assertThat(throwable) + .hasNoSuppressedExceptions() + .rootCause() + .hasMessageContainingAll("Multiple instances of FailureHandler were found at ", + "io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.SearchFailureHandler", + "io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler", + "for Hibernate Search in persistence unit . At most one instance can be assigned to each persistence unit.")); + + @Entity + @Indexed + static class MyEntity { + + @Id + @GeneratedValue + private Long id; + } + + @SearchExtension + public static class SearchFailureHandler implements FailureHandler { + @Override + public void handle(FailureContext failureContext) { + } + + @Override + public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { + } + } + + @SearchExtension + public static class AnotherSearchFailureHandler implements FailureHandler { + @Override + public void handle(FailureContext failureContext) { + } + + @Override + public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { + } + } + + @Test + public void test() { + Assertions.fail("Startup should have failed"); + } +} diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java index ca02fd677c7bc..c22f696aea546 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java @@ -28,21 +28,23 @@ private static Optional> singleExtensionBeanReferenceFor(Cl String persistenceUnitName, String backendName, String indexName) { InjectableInstance instance = extensionInstanceFor(beanType, persistenceUnitName, backendName, indexName); if (instance.isAmbiguous()) { + List ambiguousClassNames = instance.handlesStream().map(h -> h.getBean().getBeanClass().getCanonicalName()) + .toList(); if (indexName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found for Hibernate Search index %3$s in persistence unit %2$s." + "Multiple instances of %1$s were found at %2$s for Hibernate Search index %3$s in persistence unit %4$s." + " At most one instance can be assigned to each index.", - beanType.getSimpleName(), persistenceUnitName, indexName)); + beanType.getSimpleName(), ambiguousClassNames, indexName, persistenceUnitName)); } else if (backendName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found for Hibernate Search backend %3$s in persistence unit %2$s." + "Multiple instances of %1$s were found at %2$s for Hibernate Search backend %3$s in persistence unit %4$s." + " At most one instance can be assigned to each backend.", - beanType.getSimpleName(), persistenceUnitName, backendName)); + beanType.getSimpleName(), ambiguousClassNames, backendName, persistenceUnitName)); } else { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found for Hibernate Search in persistence unit %2$s." + "Multiple instances of %1$s were found at %2$s for Hibernate Search in persistence unit %3$s." + " At most one instance can be assigned to each persistence unit.", - beanType.getSimpleName(), persistenceUnitName)); + beanType.getSimpleName(), ambiguousClassNames, persistenceUnitName)); } } return instance.isResolvable() ? Optional.of(new ArcBeanReference<>(instance.getHandle().getBean())) : Optional.empty(); From 8c0d7e6586f59f185d9faf7058b6a902edb47c1d Mon Sep 17 00:00:00 2001 From: peubouzon Date: Sun, 28 Jul 2024 21:14:28 -0300 Subject: [PATCH 3/4] Improve message when multiple PU extensions are found --- ...AmbiguousPersistenceUnitExtensionTest.java | 43 +++++++++++++++++++ .../orm/runtime/PersistenceUnitUtil.java | 7 ++- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java new file mode 100644 index 0000000000000..47dfa5e7ee70d --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java @@ -0,0 +1,43 @@ +package io.quarkus.hibernate.orm.boot; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hibernate.Interceptor; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.MyEntity; +import io.quarkus.hibernate.orm.PersistenceUnitExtension; +import io.quarkus.test.QuarkusUnitTest; + +public class AmbiguousPersistenceUnitExtensionTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClass(MyEntity.class) + .addClass(PersistenceUnitInterceptor.class) + .addClass(AnotherPersistenceUnitInterceptor.class)) + .withConfigurationResource("application.properties") + .assertException(throwable -> assertThat(throwable) + .hasNoSuppressedExceptions() + .rootCause() + .hasMessageContainingAll("Multiple instances of Interceptor were found at ", + "io.quarkus.hibernate.orm.boot.AmbiguousPersistenceUnitExtensionTest.PersistenceUnitInterceptor", + "io.quarkus.hibernate.orm.boot.AmbiguousPersistenceUnitExtensionTest.AnotherPersistenceUnitInterceptor", + "for persistence unit . At most one instance can be assigned to each persistence unit.")); + + @PersistenceUnitExtension + public static class PersistenceUnitInterceptor implements Interceptor { + } + + @PersistenceUnitExtension + public static class AnotherPersistenceUnitInterceptor implements Interceptor { + } + + @Test + public void test() { + Assertions.fail("Startup should have failed"); + } +} diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java index a3194b02f77ad..b751859036c4a 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java @@ -3,6 +3,7 @@ import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Comparator; +import java.util.List; import java.util.Locale; import jakarta.enterprise.inject.Default; @@ -30,10 +31,12 @@ public static InjectableInstance singleExtensionInstanceForPersistenceUni InjectableInstance instance = extensionInstanceForPersistenceUnit(beanType, persistenceUnitName, additionalQualifiers); if (instance.isAmbiguous()) { + List ambiguousClassNames = instance.handlesStream().map(h -> h.getBean().getBeanClass().getCanonicalName()) + .toList(); throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found for persistence unit %2$s. " + "Multiple instances of %1$s were found at %2$s for persistence unit %3$s. " + "At most one instance can be assigned to each persistence unit.", - beanType.getSimpleName(), persistenceUnitName)); + beanType.getSimpleName(), ambiguousClassNames, persistenceUnitName)); } return instance; } From 25626f31c9f8a1017dd73bc22d9d45d08cd6f92c Mon Sep 17 00:00:00 2001 From: peubouzon Date: Mon, 29 Jul 2024 06:52:57 -0300 Subject: [PATCH 4/4] Improve error message readability. --- .../AmbiguousPersistenceUnitExtensionTest.java | 6 +++--- .../orm/runtime/PersistenceUnitUtil.java | 6 +++--- .../boot/AmbiguousSearchExtensionTest.java | 7 ++++--- .../runtime/bean/HibernateSearchBeanUtil.java | 18 +++++++++--------- .../boot/AmbiguousSearchExtensionTest.java | 7 ++++--- .../runtime/bean/HibernateSearchBeanUtil.java | 16 ++++++++-------- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java index 47dfa5e7ee70d..9a96923ca6c69 100644 --- a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java @@ -23,10 +23,10 @@ public class AmbiguousPersistenceUnitExtensionTest { .assertException(throwable -> assertThat(throwable) .hasNoSuppressedExceptions() .rootCause() - .hasMessageContainingAll("Multiple instances of Interceptor were found at ", + .hasMessageContainingAll("Multiple instances of Interceptor were found for persistence unit .", + "At most one instance can be assigned to each persistence unit. Instances found:", "io.quarkus.hibernate.orm.boot.AmbiguousPersistenceUnitExtensionTest.PersistenceUnitInterceptor", - "io.quarkus.hibernate.orm.boot.AmbiguousPersistenceUnitExtensionTest.AnotherPersistenceUnitInterceptor", - "for persistence unit . At most one instance can be assigned to each persistence unit.")); + "io.quarkus.hibernate.orm.boot.AmbiguousPersistenceUnitExtensionTest.AnotherPersistenceUnitInterceptor")); @PersistenceUnitExtension public static class PersistenceUnitInterceptor implements Interceptor { diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java index b751859036c4a..ec237c1e50bb0 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitUtil.java @@ -34,9 +34,9 @@ public static InjectableInstance singleExtensionInstanceForPersistenceUni List ambiguousClassNames = instance.handlesStream().map(h -> h.getBean().getBeanClass().getCanonicalName()) .toList(); throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found at %2$s for persistence unit %3$s. " - + "At most one instance can be assigned to each persistence unit.", - beanType.getSimpleName(), ambiguousClassNames, persistenceUnitName)); + "Multiple instances of %1$s were found for persistence unit %2$s. " + + "At most one instance can be assigned to each persistence unit. Instances found: %3$s", + beanType.getSimpleName(), persistenceUnitName, ambiguousClassNames)); } return instance; } diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java index b0942ad6484d8..659eaba457d78 100644 --- a/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java @@ -29,10 +29,11 @@ public class AmbiguousSearchExtensionTest { .assertException(throwable -> assertThat(throwable) .hasNoSuppressedExceptions() .rootCause() - .hasMessageContainingAll("Multiple instances of FailureHandler were found at ", + .hasMessageContainingAll( + "Multiple instances of FailureHandler were found for Hibernate Search in persistence unit .", + "At most one instance can be assigned to each persistence unit. Instances found:", "io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.SearchFailureHandler", - "io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler", - "for Hibernate Search in persistence unit . At most one instance can be assigned to each persistence unit.")); + "io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler")); @Entity @Indexed diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java index c22f696aea546..5607bb1f76108 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java @@ -32,19 +32,19 @@ private static Optional> singleExtensionBeanReferenceFor(Cl .toList(); if (indexName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found at %2$s for Hibernate Search index %3$s in persistence unit %4$s." - + " At most one instance can be assigned to each index.", - beanType.getSimpleName(), ambiguousClassNames, indexName, persistenceUnitName)); + "Multiple instances of %1$s were found for Hibernate Search index %2$s in persistence unit %3$s." + + " At most one instance can be assigned to each index. Instances found: %4$s", + beanType.getSimpleName(), indexName, persistenceUnitName, ambiguousClassNames)); } else if (backendName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found at %2$s for Hibernate Search backend %3$s in persistence unit %4$s." - + " At most one instance can be assigned to each backend.", - beanType.getSimpleName(), ambiguousClassNames, backendName, persistenceUnitName)); + "Multiple instances of %1$s were found for Hibernate Search backend %2$s in persistence unit %3$s." + + " At most one instance can be assigned to each backend. Instances found: %4$s", + beanType.getSimpleName(), backendName, persistenceUnitName, ambiguousClassNames)); } else { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found at %2$s for Hibernate Search in persistence unit %3$s." - + " At most one instance can be assigned to each persistence unit.", - beanType.getSimpleName(), ambiguousClassNames, persistenceUnitName)); + "Multiple instances of %1$s were found for Hibernate Search in persistence unit %2$s." + + " At most one instance can be assigned to each persistence unit. Instances found: %3$s", + beanType.getSimpleName(), persistenceUnitName, ambiguousClassNames)); } } return instance.isResolvable() ? Optional.of(new ArcBeanReference<>(instance.getHandle().getBean())) : Optional.empty(); diff --git a/extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java b/extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java index de35daca8c3d3..658db29fda698 100644 --- a/extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java +++ b/extensions/hibernate-search-standalone-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java @@ -26,10 +26,11 @@ public class AmbiguousSearchExtensionTest { .assertException(throwable -> assertThat(throwable) .hasNoSuppressedExceptions() .rootCause() - .hasMessageContainingAll("Multiple instances of FailureHandler were found at ", + .hasMessageContainingAll( + "Multiple instances of FailureHandler were found for Hibernate Search Standalone.", + "At most one instance can be assigned. Instances found:", "io.quarkus.hibernate.search.standalone.elasticsearch.test.boot.AmbiguousSearchExtensionTest.SearchFailureHandler", - "io.quarkus.hibernate.search.standalone.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler", - "for Hibernate Search Standalone. At most one instance can be assigned.")); + "io.quarkus.hibernate.search.standalone.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler")); @SearchEntity @Indexed diff --git a/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java b/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java index b10d32265a511..6afed7030a1d0 100644 --- a/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java +++ b/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java @@ -32,18 +32,18 @@ private static Optional> singleExtensionBeanReferenceFor(Cl .toList(); if (indexName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found at %2$s for Hibernate Search Standalone index %3$s." - + " At most one instance can be assigned to each index.", - beanType.getSimpleName(), ambiguousClassNames, indexName)); + "Multiple instances of %1$s were found for Hibernate Search Standalone index %2$s." + + " At most one instance can be assigned to each index. Instances found: %3$s", + beanType.getSimpleName(), indexName, ambiguousClassNames)); } else if (backendName != null) { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found at %2$s for Hibernate Search Standalone backend %3$s." - + " At most one instance can be assigned to each backend.", - beanType.getSimpleName(), ambiguousClassNames, backendName)); + "Multiple instances of %1$s were found for Hibernate Search Standalone backend %2$s." + + " At most one instance can be assigned to each backend. Instances found: %3$s", + beanType.getSimpleName(), backendName, ambiguousClassNames)); } else { throw new IllegalStateException(String.format(Locale.ROOT, - "Multiple instances of %1$s were found at %2$s for Hibernate Search Standalone." - + " At most one instance can be assigned.", + "Multiple instances of %1$s were found for Hibernate Search Standalone." + + " At most one instance can be assigned. Instances found: %2$s", beanType.getSimpleName(), ambiguousClassNames)); } }