Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Bug Fixes

- [Breaking] `DatabricksError` now correctly exposes all Databricks error details types. This change is a breaking change for users depending on the `ErrorDetail` class. The same information can be accessed from `ErrorDetails.errorInfo`.

### Documentation

### Internal Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.databricks.sdk.core;

import com.databricks.sdk.core.error.ErrorDetail;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import com.databricks.sdk.core.error.details.ErrorDetails;

/**
* The result of checking whether {@code ApiClient} should retry a request.
Expand All @@ -17,45 +14,35 @@ public class DatabricksError extends DatabricksException {
private final Throwable cause;
private final String errorCode;
private final int statusCode;

private final List<ErrorDetail> details;
private final ErrorDetails errorDetails;

public DatabricksError(int statusCode) {
this("", "OK", statusCode, null, Collections.emptyList());
this("", "OK", statusCode, null, ErrorDetails.builder().build());
}

public DatabricksError(String errorCode, String message) {
this(errorCode, message, 400, null, Collections.emptyList());
this(errorCode, message, 400, null, ErrorDetails.builder().build());
}

public DatabricksError(String errorCode, String message, int statusCode) {
this(errorCode, message, statusCode, null, Collections.emptyList());
this(errorCode, message, statusCode, null, ErrorDetails.builder().build());
}

public DatabricksError(String errorCode, int statusCode, Throwable cause) {
this(errorCode, cause.getMessage(), statusCode, cause, Collections.emptyList());
this(errorCode, cause.getMessage(), statusCode, cause, ErrorDetails.builder().build());
}

public DatabricksError(
String errorCode, String message, int statusCode, List<ErrorDetail> details) {
public DatabricksError(String errorCode, String message, int statusCode, ErrorDetails details) {
this(errorCode, message, statusCode, null, details);
}

private DatabricksError(
String errorCode,
String message,
int statusCode,
Throwable cause,
List<ErrorDetail> details) {
String errorCode, String message, int statusCode, Throwable cause, ErrorDetails details) {
super(message, cause);
this.errorCode = errorCode;
this.cause = cause;
this.statusCode = statusCode;
this.details = details == null ? Collections.emptyList() : details;
}

public List<ErrorDetail> getErrorInfo() {
return this.getDetailsByType("type.googleapis.com/google.rpc.ErrorInfo");
this.errorDetails = details == null ? ErrorDetails.builder().build() : details;
}

public String getErrorCode() {
Expand All @@ -70,7 +57,7 @@ public Throwable getCause() {
return cause;
}

List<ErrorDetail> getDetailsByType(String type) {
return this.details.stream().filter(e -> e.getType().equals(type)).collect(Collectors.toList());
public ErrorDetails getErrorDetails() {
return errorDetails;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.databricks.sdk.core.error;

import com.databricks.sdk.core.DatabricksError;
import com.databricks.sdk.core.error.details.ErrorDetails;
import com.databricks.sdk.core.http.Response;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -13,12 +13,12 @@ abstract class AbstractErrorMapper {

@FunctionalInterface
protected interface ErrorCodeRule {
DatabricksError create(String message, List<ErrorDetail> details);
DatabricksError create(String message, ErrorDetails details);
}

@FunctionalInterface
protected interface StatusCodeRule {
DatabricksError create(String errorCode, String message, List<ErrorDetail> details);
DatabricksError create(String errorCode, String message, ErrorDetails details);
}

public DatabricksError apply(Response resp, ApiErrorBody errorBody) {
Expand All @@ -35,7 +35,7 @@ public DatabricksError apply(Response resp, ApiErrorBody errorBody) {
int code = resp.getStatusCode();
String message = errorBody.getMessage();
String errorCode = errorBody.getErrorCode();
List<ErrorDetail> details = errorBody.getErrorDetails();
ErrorDetails details = errorBody.getErrorDetails();
if (errorCodeMapping.containsKey(errorCode)) {
return errorCodeMapping.get(errorCode).create(message, details);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import com.databricks.sdk.core.error.details.ErrorDetails;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* The union of all JSON error responses from the Databricks APIs, not including HTML responses.
Expand All @@ -20,7 +17,7 @@ public class ApiErrorBody {
private String scimStatus;
private String scimType;
private String api12Error;
private List<ErrorDetail> errorDetails;
private ErrorDetails errorDetails;

public ApiErrorBody() {}

Expand Down Expand Up @@ -48,14 +45,14 @@ public ApiErrorBody(
this.scimStatus = scimStatus;
this.scimType = scimType;
this.api12Error = api12Error;
this.errorDetails = fromDetails(errorDetails);
this.errorDetails = errorDetails;
}

public List<ErrorDetail> getErrorDetails() {
public ErrorDetails getErrorDetails() {
return errorDetails;
}

public void setErrorDetails(List<ErrorDetail> errorDetails) {
public void setErrorDetails(ErrorDetails errorDetails) {
this.errorDetails = errorDetails;
}

Expand Down Expand Up @@ -106,26 +103,4 @@ public String getApi12Error() {
public void setApi12Error(String api12Error) {
this.api12Error = api12Error;
}

/**
* Converts the error details to a list of ErrorDetail objects. This only supports the ErrorInfo
* type.
*
* @param details The error details to convert.
* @return A list of ErrorDetail objects.
*/
private static List<ErrorDetail> fromDetails(ErrorDetails details) {
if (details == null) {
return Collections.emptyList();
}
if (!details.errorInfo().isPresent()) {
return Collections.emptyList();
}
return Arrays.asList(
new ErrorDetail(
"type.googleapis.com/google.rpc.ErrorInfo",
details.errorInfo().get().reason(),
details.errorInfo().get().domain(),
details.errorInfo().get().metadata()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.databricks.sdk.core.DatabricksError;
import com.databricks.sdk.core.DatabricksException;
import com.databricks.sdk.core.error.details.ErrorDetails;
import com.databricks.sdk.core.http.Response;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -52,7 +52,7 @@ private static ApiErrorBody readErrorFromResponse(Response response) {
errorBody.setErrorCode("SCIM_" + errorBody.getScimStatus());
}
if (errorBody.getErrorDetails() == null) {
errorBody.setErrorDetails(Collections.emptyList());
errorBody.setErrorDetails(ErrorDetails.builder().build());
}
return errorBody;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.databricks.sdk.core.DatabricksError;
import com.databricks.sdk.core.DatabricksException;
import com.databricks.sdk.core.error.details.ErrorDetails;
import com.databricks.sdk.core.http.Response;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.regex.Pattern;

public class ErrorOverride<T extends DatabricksError> {
Expand Down Expand Up @@ -68,7 +68,7 @@ public T makeError(ApiErrorBody body) {
// All errors have a 2-argument constructor for the message and the error body.
if (parameterTypes.length == 2
&& parameterTypes[0].equals(String.class)
&& parameterTypes[1].equals(List.class)) {
&& parameterTypes[1].equals(ErrorDetails.class)) {
try {
return (T) constructor.newInstance(body.getMessage(), body.getErrorDetails());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.databricks.sdk.core.error;

import com.databricks.sdk.core.DatabricksEnvironment;
import com.databricks.sdk.core.error.details.ErrorDetails;
import com.databricks.sdk.core.http.Response;
import com.databricks.sdk.core.utils.Cloud;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -61,6 +61,6 @@ static PrivateLinkValidationError createPrivateLinkValidationError(Response resp
DatabricksEnvironment env =
DatabricksEnvironment.getEnvironmentFromHostname(resp.getUrl().getHost());
PrivateLinkInfo info = PRIVATE_LINK_INFOS.get(env.getCloud());
return new PrivateLinkValidationError(info.errorMessage(), Collections.emptyList());
return new PrivateLinkValidationError(info.errorMessage(), ErrorDetails.builder().build());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.databricks.sdk.core.error;

import com.databricks.sdk.core.error.details.ErrorDetails;
import com.databricks.sdk.core.error.platform.PermissionDenied;
import java.util.List;

public class PrivateLinkValidationError extends PermissionDenied {
public PrivateLinkValidationError(String message, List<ErrorDetail> details) {
public PrivateLinkValidationError(String message, ErrorDetails details) {
super("PRIVATE_LINK_VALIDATION_ERROR", message, details);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public abstract class DebugInfo {
* @return a new builder instance
*/
public static Builder builder() {
return new AutoValue_DebugInfo.Builder();
return new AutoValue_DebugInfo.Builder().setStackEntries(Collections.emptyList());
}

/** Builder for constructing DebugInfo instances. */
Expand Down Expand Up @@ -108,15 +108,6 @@ public abstract static class Builder {
*
* @return a new DebugInfo instance
*/
public DebugInfo build() {
if (stackEntries() == null) {
setStackEntries(Collections.emptyList());
}
return autoBuild();
}

abstract List<String> stackEntries();

abstract DebugInfo autoBuild();
public abstract DebugInfo build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.auto.value.AutoValue;
import java.util.Collections;
import java.util.List;
Expand All @@ -13,6 +14,7 @@
*/
@AutoValue
@JsonDeserialize(using = ErrorDetailsDeserializer.class)
@JsonSerialize(using = ErrorDetailsSerializer.class)
public abstract class ErrorDetails {

public abstract Optional<ErrorInfo> errorInfo();
Expand All @@ -36,7 +38,7 @@ public abstract class ErrorDetails {
public abstract List<JsonNode> unknownDetails();

public static Builder builder() {
return new AutoValue_ErrorDetails.Builder();
return new AutoValue_ErrorDetails.Builder().setUnknownDetails(Collections.emptyList());
}

@AutoValue.Builder
Expand All @@ -61,17 +63,6 @@ public abstract static class Builder {

public abstract Builder setUnknownDetails(List<JsonNode> unknownDetails);

abstract List<JsonNode> unknownDetails();

abstract ErrorDetails autoBuild();

public ErrorDetails build() {
try {
unknownDetails();
} catch (IllegalStateException e) {
setUnknownDetails(Collections.emptyList());
}
return autoBuild();
}
public abstract ErrorDetails build();
}
}
Loading
Loading