Skip to content

SOLR-17549: v2 SolrRequest/SolrResponse should throw exception on error#4183

Open
gerlowskija wants to merge 3 commits intoapache:mainfrom
gerlowskija:SOLR-17549-v2-error-reporting
Open

SOLR-17549: v2 SolrRequest/SolrResponse should throw exception on error#4183
gerlowskija wants to merge 3 commits intoapache:mainfrom
gerlowskija:SOLR-17549-v2-error-reporting

Conversation

@gerlowskija
Copy link
Contributor

https://issues.apache.org/jira/browse/SOLR-17549

Description

Prior to this commit our generated v2 SolrRequest implementations only
reported errors in the POJO itself. A failure response from Solr
wouldn't trigger a RemoteSolrException as SolrJ users are used to with
our v1 APIs.

This was tough for users to remember to do, and even when done properly
ends up looking verbose and ugly.

Solution

This commit updates our v2 SolrJ code to throw RemoteSolrException when
error-responses are encountered.

It relies on a pre-existing attempt at error detection already present in our
SolrClient implementations. Code in many of our clients already attempts to
detect these errors by looking for a 'NamedList' key, "error", which it
(incorrectly) assumed would be present in the v2 case but which isn't
populated by the ResponseParser that our v2 SolrRequest/SolrResponse
implementations use by default.

This commit updates JacksonDatabindResponseParser to populate this
"error" key that SolrClient's were looking for, which in turn enables the
clients to correctly throw RemoteSolrException in these cases.

Tests

Unit tests for JacksonDatabindResponseParser in JacksonDatabindResponseParserTest. An integration test validating the end-to-end behavior has also been added to V2ApiIntegrationTest.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added a changelog entry for my change

Prior to this commit our generated v2 SolrRequest implementations only
reported errors in the POJO itself.  A failure response from Solr
wouldn't trigger a RemoteSolrException as SolrJ users are used to with
our v1 APIs.

Error detection in our SolrClient implementations attempted to
detect-and-throw in these v2 cases, but that detection was keying off of
a 'NamedList' key that wasn't being populated by
JacksonDatabindResponseParser (which is used for these v2
SolrRequest/Response pairs).

This commit updates JacksonDatabindResponseParser to populate this
"error" key that SolrClient's were looking for.
Copy link
Contributor

@epugh epugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with two small comments... This is exciting!

}

private void assertRSECodeAndMessage(
RemoteSolrException rse, int expectedCode, String... expectedMessagePices) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ding ding, I found a typo... time to pick up the pieces. heh heh.

assertRSECodeAndMessage(ex, 400, "Could not find collection", "collection-does-not-exist");
}

private void assertRSECodeAndMessage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any value in testing here the other ways of making a query like GenericSolrRequest? That it alos throws a 400?

public void testErrorResponseSurfacesErrorAtTopLevel() throws IOException {
final var parser = new JacksonDataBindResponseParser<>(SolrJerseyResponse.class);
final var json =
"{"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been enjoying use the triple "double quotes" to not have all this string escaping and make reading multiline JSON easier.

@epugh epugh changed the title Solr 17549 v2 error reporting SOLR-17549: v2 error reporting Mar 3, 2026
@gerlowskija gerlowskija changed the title SOLR-17549: v2 error reporting SOLR-17549: v2 SolrRequest/SolrResponse should throw exception on error Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants