Skip to content

Commit

Permalink
Improve error message readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
peuBouzon committed Jul 29, 2024
1 parent 8c0d7e6 commit 25626f3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <default>.",
"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 <default>. 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public static <T> InjectableInstance<T> singleExtensionInstanceForPersistenceUni
List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <default>.",
"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 <default>. At most one instance can be assigned to each persistence unit."));
"io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler"));

@Entity
@Indexed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ private static <T> Optional<BeanReference<T>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ private static <T> Optional<BeanReference<T>> 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));
}
}
Expand Down

0 comments on commit 25626f3

Please sign in to comment.