Skip to content

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

Merged
gerlowskija merged 5 commits intoapache:mainfrom
gerlowskija:SOLR-17549-v2-error-reporting
Mar 6, 2026
Merged

SOLR-17549: v2 SolrRequest/SolrResponse should throw exception on error#4183
gerlowskija merged 5 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.

@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
@gerlowskija
Copy link
Contributor Author

Alright, addressed your comments @epugh - lmk when you get a chance to take another look. I'll aim to merge this Friday or so to get you unblocked on some of the tests you were hoping to write using the generated SolrJ objects.

@Test
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.

so nitpucky, but triple double uqotes?

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!

If you wanted to merge this, and then take one of the new V2 conversions and update it in light of htis, I'd lvoe to see that. Maybe the CLI v1 to v2 PR?

@gerlowskija
Copy link
Contributor Author

If you wanted to merge this, and then take one of the new V2 conversions and update it in light of htis,

This PR does do a bit of that updating I think? Albeit in test code rather than, say, the CLI. See the RenameCoreAPITest changes in this PR if you're looking for examples?

Or is it less about having syntax examples to reference and more about getting additional hands helping move those PRs forward?

In any case - going to merge this now and we can iterate on those other PRs separately.

@epugh
Copy link
Contributor

epugh commented Mar 6, 2026

Great! I think once this is merged, and I update the CLI migration PR, I just want you to re-review that we are using this new logic properly... And since I don't think I ever took into account in the CLI migration that the v2 could/was different, then the PR should be just fine once this is in!

@gerlowskija gerlowskija merged commit 674e3d1 into apache:main Mar 6, 2026
5 of 6 checks passed
@gerlowskija gerlowskija deleted the SOLR-17549-v2-error-reporting branch March 6, 2026 15:53
gerlowskija added a commit that referenced this pull request Mar 6, 2026
…or (#4183)

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.
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