diff --git a/server/src/main/java/org/apache/druid/client/JsonParserIterator.java b/server/src/main/java/org/apache/druid/client/JsonParserIterator.java index 237614fb4ff..00dea3dff0e 100644 --- a/server/src/main/java/org/apache/druid/client/JsonParserIterator.java +++ b/server/src/main/java/org/apache/druid/client/JsonParserIterator.java @@ -185,8 +185,17 @@ public class JsonParserIterator implements CloseableIterator } else if (nextToken == JsonToken.START_OBJECT) { throw convertException(jp.getCodec().readValue(jp, QueryException.class)); } else { + String errMsg = jp.getValueAsString(); + if (errMsg != null) { + errMsg = errMsg.substring(0, Math.min(errMsg.length(), 192)); + } throw convertException( - new IAE("Next token wasn't a START_ARRAY, was[%s] from url[%s]", jp.getCurrentToken(), url) + new IAE( + "Next token wasn't a START_ARRAY, was[%s] from url[%s] with value[%s]", + jp.getCurrentToken(), + url, + errMsg + ) ); } } diff --git a/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java b/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java index 3ac2b4122d2..5cce3c2fd3f 100644 --- a/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java +++ b/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java @@ -316,8 +316,60 @@ public class JsonParserIteratorTest } } + public static class IAEExceptionConversionTest + { + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private String errorMessage = "pstream connect error or disconnect/reset before header"; + private String nullErrMsg = null; + + @Test + public void testNullErrorMsg() throws JsonProcessingException + { + JsonParserIterator iterator = new JsonParserIterator<>( + JAVA_TYPE, + Futures.immediateFuture( + mockErrorResponse(nullErrMsg) + ), + URL, + null, + HOST, + OBJECT_MAPPER + ); + + expectedException.expect(QueryInterruptedException.class); + expectedException.expectMessage(""); + iterator.hasNext(); + } + + @Test + public void testParsingError() throws JsonProcessingException + { + JsonParserIterator iterator = new JsonParserIterator<>( + JAVA_TYPE, + Futures.immediateFuture( + mockErrorResponse(errorMessage) + ), + URL, + null, + HOST, + OBJECT_MAPPER + ); + + expectedException.expect(QueryInterruptedException.class); + expectedException.expectMessage(errorMessage); + iterator.hasNext(); + } + } + private static InputStream mockErrorResponse(Exception e) throws JsonProcessingException { return new ByteArrayInputStream(OBJECT_MAPPER.writeValueAsBytes(e)); } + + private static InputStream mockErrorResponse(String errMsg) throws JsonProcessingException + { + return new ByteArrayInputStream(OBJECT_MAPPER.writeValueAsBytes(errMsg)); + } }