Skip to content

Commit 841b346

Browse files
authored
[Fix] Fix parsing issue in ErrorDetail (#328)
## Issue Description Exceptions are not deserialized correctly, the message field contains the response JSON and the string 'Cannot construct instance of com.databricks.sdk.core.error.ErrorDetail, problem: Cannot invoke "Object.getClass()" because "m" is null' ## Changes In ErrorDetails class, i added a null check before the unmodifiableMap is created. ## Tests Created an unit test in ApiErrorBodyDeserializationSuite.java Signed-off-by: Costin Chiulan <[email protected]>
1 parent 4d46368 commit 841b346

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public ErrorDetail(
2626
this.type = type;
2727
this.reason = reason;
2828
this.domain = domain;
29-
this.metadata = Collections.unmodifiableMap(metadata);
29+
this.metadata = metadata != null ? Collections.unmodifiableMap(metadata) : null;
3030
}
3131

3232
public String getType() {

databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ void handleUnexpectedFieldsInErrorResponse() throws JsonProcessingException {
6464
assertEquals(error.getErrorCode(), "theerrorcode");
6565
assertEquals(error.getMessage(), "themessage");
6666
}
67+
68+
@Test
69+
void handleNullMetadataFieldInErrorResponse() throws JsonProcessingException {
70+
ObjectMapper mapper = new ObjectMapper();
71+
String rawResponse =
72+
"{\"error_code\":\"METASTORE_DOES_NOT_EXIST\",\"message\":\"No metastore assigned for the current workspace.\",\"details\":[{\"@type\":\"type.googleapis.com/google.rpc.RequestInfo\",\"request_id\":\"1888e822-f1b5-4996-85eb-0d2b5cc402e6\",\"serving_data\":\"\"}]}";
73+
ApiErrorBody error = mapper.readValue(rawResponse, ApiErrorBody.class);
74+
75+
assertEquals(error.getErrorCode(), "METASTORE_DOES_NOT_EXIST");
76+
assertEquals(error.getMessage(), "No metastore assigned for the current workspace.");
77+
}
6778
}

0 commit comments

Comments
 (0)