-
Notifications
You must be signed in to change notification settings - Fork 33
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
Introduce protocol versioning #421
Changes from all commits
599b1e4
da9eb32
f5474eb
eb4189a
d0cd046
07f3441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,12 @@ | |
|
||
import javax.annotation.Nullable; | ||
|
||
import static com.vaticle.typedb.client.common.exception.ErrorMessage.Client.CLUSTER_PASSWORD_CREDENTIAL_EXPIRED; | ||
import static com.vaticle.typedb.client.common.exception.ErrorMessage.Client.CLUSTER_REPLICA_NOT_PRIMARY; | ||
import static com.vaticle.typedb.client.common.exception.ErrorMessage.Client.CLUSTER_TOKEN_CREDENTIAL_INVALID; | ||
import static com.vaticle.typedb.client.common.exception.ErrorMessage.Client.RPC_METHOD_UNAVAILABLE; | ||
import static com.vaticle.typedb.client.common.exception.ErrorMessage.Client.UNABLE_TO_CONNECT; | ||
|
||
public class TypeDBClientException extends RuntimeException { | ||
|
||
// TODO: propagate exception from the server side in a less-brittle way | ||
|
@@ -48,14 +54,16 @@ public TypeDBClientException(String message, Throwable cause) { | |
} | ||
|
||
public static TypeDBClientException of(StatusRuntimeException sre) { | ||
if (isRstStream(sre)) { | ||
return new TypeDBClientException(ErrorMessage.Client.UNABLE_TO_CONNECT); | ||
if (isUnimplementedMethod(sre)) { | ||
return new TypeDBClientException(RPC_METHOD_UNAVAILABLE, sre.getStatus().getDescription()); | ||
} else if (isRstStream(sre)) { | ||
return new TypeDBClientException(UNABLE_TO_CONNECT); | ||
} else if (isReplicaNotPrimary(sre)) { | ||
return new TypeDBClientException(ErrorMessage.Client.CLUSTER_REPLICA_NOT_PRIMARY); | ||
return new TypeDBClientException(CLUSTER_REPLICA_NOT_PRIMARY); | ||
} else if (isTokenCredentialInvalid(sre)) { | ||
return new TypeDBClientException(ErrorMessage.Client.CLUSTER_TOKEN_CREDENTIAL_INVALID); | ||
return new TypeDBClientException(CLUSTER_TOKEN_CREDENTIAL_INVALID); | ||
} else if (isPasswordCredentialExpired(sre)) { | ||
return new TypeDBClientException(ErrorMessage.Client.CLUSTER_PASSWORD_CREDENTIAL_EXPIRED); | ||
return new TypeDBClientException(CLUSTER_PASSWORD_CREDENTIAL_EXPIRED); | ||
} else { | ||
return new TypeDBClientException(sre.getStatus().getDescription(), sre); | ||
} | ||
|
@@ -85,6 +93,11 @@ private static boolean isPasswordCredentialExpired(StatusRuntimeException status | |
statusRuntimeException.getStatus().getDescription() != null && | ||
statusRuntimeException.getStatus().getDescription().contains(CLUSTER_PASSWORD_CREDENTIAL_EXPIRED_ERROR_CODE); | ||
} | ||
|
||
private static boolean isUnimplementedMethod(StatusRuntimeException statusRuntimeException) { | ||
return statusRuntimeException.getStatus().getCode() == Status.Code.UNIMPLEMENTED; | ||
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. This is a sufficient but not necessary condition for a client-server mismatch error. It's also possible that we send a request message with an RPC code that is implemented, but carries a different semantic meaning in this protocol version. Do we perform some kind of handshake anywhere to verify the protocol version? I notice 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. Yep, and it throws basically the equivalent error message if it is a mismatch :) between the two of them we should get pretty good coverage of client-protocol mismatches -> useful errors the users can resolve by themselves. |
||
} | ||
|
||
public String getName() { | ||
return this.getClass().getName(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message could be friendlier, something like
"The server does not support this method. Please ensure that the TypeDB Client and TypeDB Server versions are compatible ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will push an update, thank you!