Skip to content

Commit f88ff86

Browse files
committed
PLUGIN-1936 : Improve exception handling for nextKeyValue() method
1 parent a04dc6c commit f88ff86

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/e2e-test/java/io/cdap/plugin/servicenowsink/actions/ServiceNowSinkPropertiesPageActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class ServiceNowSinkPropertiesPageActions {
5252
private static Gson gson = new Gson();
5353

5454
public static void getRecordFromServiceNowTable(String query, String tableName)
55-
throws ServiceNowAPIException {
55+
throws ServiceNowAPIException, IOException {
5656
config = new ServiceNowSourceConfig(
5757
"", "", "", "", "",
5858
System.getenv("SERVICE_NOW_CLIENT_ID"),

src/main/java/io/cdap/plugin/servicenow/source/ServiceNowBaseRecordReader.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@ public boolean nextKeyValue() throws IOException {
8787
this.row = gson.fromJson(jsonReader, JsonObject.class); // assign row
8888
pos++;
8989
return true;
90+
} else if (token == JsonToken.END_ARRAY) {
91+
// This is the only "Normal" end of a page
92+
closeCurrentPage();
93+
return false;
94+
} else {
95+
// If we get here, the JSON is malformed or truncated
96+
throw new IOException("Unexpected JSON token " + token + " at position " + pos);
9097
}
91-
closeCurrentPage();
92-
return false;
9398
}
9499

95100
public boolean openNextPage() throws IOException, ServiceNowAPIException {
@@ -110,9 +115,8 @@ public boolean openNextPage() throws IOException, ServiceNowAPIException {
110115
top = jsonReader.peek();
111116
LOG.debug("Peeking JSON token for table {}: {}", tableName, top);
112117
} catch (IOException e) {
113-
LOG.warn("Unexpected closure of stream while peeking JSON token for table {}", tableName, e);
114118
closeCurrentPage();
115-
return false;
119+
throw new IOException("Unexpected closure of stream while peeking JSON token for table {}" + tableName, e);
116120
}
117121
if (top == JsonToken.BEGIN_OBJECT) {
118122
jsonReader.beginObject();

0 commit comments

Comments
 (0)