-
Notifications
You must be signed in to change notification settings - Fork 833
SOLR-17549: v2 SolrRequest/SolrResponse should throw exception on error #4183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gerlowskija
merged 5 commits into
apache:main
from
gerlowskija:SOLR-17549-v2-error-reporting
Mar 6, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d3f553d
SOLR-17549: v2 SolrRequests throw RSE on error
gerlowskija cb34e4c
Add changelog entry
gerlowskija 81f6615
Address test failures
gerlowskija 4856c24
Address review comments, rd 1
gerlowskija d6a77e1
Merge branch 'main' into SOLR-17549-v2-error-reporting
gerlowskija File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| title: SOLR-17549 - v2 SolrRequest/SolrResponse classes now report errors identically to their v1 counterparts | ||
| type: fixed | ||
| authors: | ||
| - name: Jason Gerlowski | ||
| links: | ||
| - name: SOLR-17549 | ||
| url: https://issues.apache.org/jira/browse/SOLR-17549 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
...rc/test/org/apache/solr/client/solrj/response/json/JacksonDataBindResponseParserTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.solr.client.solrj.response.json; | ||
|
|
||
| import static org.hamcrest.Matchers.instanceOf; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Map; | ||
| import org.apache.solr.SolrTestCase; | ||
| import org.apache.solr.client.api.model.SolrJerseyResponse; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.junit.Test; | ||
|
|
||
| /** Unit tests for {@link JacksonDataBindResponseParser} */ | ||
| public class JacksonDataBindResponseParserTest extends SolrTestCase { | ||
|
|
||
| @Test | ||
| public void testSuccessfulResponseHasNoErrorKey() throws IOException { | ||
| final var parser = new JacksonDataBindResponseParser<>(SolrJerseyResponse.class); | ||
| final var json = "{\"responseHeader\":{\"status\":0,\"QTime\":5}}"; | ||
|
|
||
| final NamedList<Object> result = parser.processResponse(toStream(json), null); | ||
|
|
||
| assertNotNull(result.get("response")); | ||
| assertThat(result.get("response"), instanceOf(SolrJerseyResponse.class)); | ||
| assertNull("No 'error' key expected on success", result.get("error")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testErrorResponseSurfacesErrorAtTopLevel() throws IOException { | ||
| final var parser = new JacksonDataBindResponseParser<>(SolrJerseyResponse.class); | ||
| final var json = | ||
| "{" | ||
|
epugh marked this conversation as resolved.
|
||
| + "\"responseHeader\":{\"status\":400,\"QTime\":3}," | ||
| + "\"error\":{" | ||
| + " \"code\":400," | ||
| + " \"errorClass\":\"org.apache.solr.common.SolrException\"," | ||
| + " \"msg\":\"Bad collection name\"" | ||
| + "}" | ||
| + "}"; | ||
|
|
||
| final NamedList<Object> result = parser.processResponse(toStream(json), null); | ||
|
|
||
| // The deserialized POJO is present under "response" | ||
| assertNotNull(result.get("response")); | ||
| assertThat(result.get("response"), instanceOf(SolrJerseyResponse.class)); | ||
| final var responsePojo = (SolrJerseyResponse) result.get("response"); | ||
|
|
||
| // Error is present in the deserialized POJO | ||
| assertNotNull("Error should be populated in the POJO", responsePojo.error); | ||
|
|
||
| // Error is also present on NL for clients to detect | ||
| assertNotNull(result.get("error")); | ||
| assertThat(result.get("error"), instanceOf(Map.class)); | ||
| @SuppressWarnings("unchecked") | ||
| final var topLevelError = (Map<String, Object>) result.get("error"); | ||
| assertEquals(400, topLevelError.get("code")); | ||
| assertEquals("org.apache.solr.common.SolrException", topLevelError.get("errorClass")); | ||
| assertEquals("Bad collection name", topLevelError.get("msg")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testErrorResponseIncludesMetadataAtTopLevel() throws IOException { | ||
| final var parser = new JacksonDataBindResponseParser<>(SolrJerseyResponse.class); | ||
| final var json = | ||
| """ | ||
| { | ||
| "responseHeader":{ | ||
| "status":500, | ||
| "QTime":1 | ||
| }, | ||
| "error": { | ||
| "code":500, | ||
| "errorClass": "org.apache.solr.common.SolrException", | ||
| "msg": "Internal error", | ||
| "metadata":{ | ||
| "error-class": "org.apache.solr.common.SolrException", | ||
| "root-error-class": "java.lang.IllegalStateException" | ||
| } | ||
| } | ||
| }"""; | ||
|
|
||
| final NamedList<Object> result = parser.processResponse(toStream(json), null); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| final var topLevelError = (Map<String, Object>) result.get("error"); | ||
| assertNotNull(topLevelError); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| final var metadata = (Map<String, Object>) topLevelError.get("metadata"); | ||
| assertNotNull("Metadata must be present for RemoteSolrException to extract it", metadata); | ||
| assertEquals("org.apache.solr.common.SolrException", metadata.get("error-class")); | ||
| assertEquals("java.lang.IllegalStateException", metadata.get("root-error-class")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNonJerseyResponseTypeIsUnaffected() throws IOException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure what the practical impact of this is, or if its even worth testing what was out of scope. |
||
| // A parser bound to a plain POJO (i.e. not SolrJerseyResponse) must not add an "error" key | ||
| final var parser = new JacksonDataBindResponseParser<>(PlainPojo.class); | ||
| final var json = "{\"value\":\"hello\"}"; | ||
|
|
||
| final NamedList<Object> result = parser.processResponse(toStream(json), null); | ||
|
|
||
| assertNotNull(result.get("response")); | ||
| assertThat(result.get("response"), instanceOf(PlainPojo.class)); | ||
| assertNull("Error extraction only occurs for SolrJerseyResponse types", result.get("error")); | ||
| } | ||
|
|
||
| // Minimal POJO for the non-SolrJerseyResponse test above | ||
| public static class PlainPojo { | ||
| public String value; | ||
| } | ||
|
|
||
| private static ByteArrayInputStream toStream(String json) { | ||
| return new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.