Provide contextual information about the projection definition when it cannot be applied to an index

Description

When, in a search query definition, someone calls .select(MyProjectionClass.class), it’s possible that this class’s @ProjectionConstructor references fields that don’t exist, or are not projectable, and that will lead to an exception being thrown.

That exception includes all the necessary information about the problem to fix (field name, why it cannot be targeted, etc.), but it lacks information about why that problem occurred, i.e. which projection definition could not be applied exactly. That information would be especially useful in the case of nested @ProjectionConstructors.

Concretely, this would mean catching SearchException in org.hibernate.search.mapper.pojo.search.definition.impl.PojoConstructorProjectionDefinition#apply and throwing another SearchException with a message such as “Could not apply projection constructor <name>: <message from the cause>”, (of course we’d also use the caught exception as the cause). We may have to tune this a bit to avoid very complicated messages when there are multiple levels of projection constructor nesting.

Activity

Show:
Fixed

Assignee

Reporter

Components

Sprint

Fix versions

Priority

Created August 10, 2022 at 9:56 AM
Updated July 3, 2023 at 11:27 AM
Resolved October 20, 2022 at 9:45 AM
Loading...