Skip to content

Commit

Permalink
Add preview support for GQL Errors (#1559)
Browse files Browse the repository at this point in the history
This update brings initial support for GQL Errors.
  • Loading branch information
injectives authored Oct 11, 2024
1 parent d0211a0 commit 345503b
Show file tree
Hide file tree
Showing 85 changed files with 2,851 additions and 173 deletions.
2 changes: 1 addition & 1 deletion benchkit-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<artifactId>neo4j-java-driver-parent</artifactId>
<groupId>org.neo4j.driver</groupId>
<version>5.25-SNAPSHOT</version>
<version>5.26-SNAPSHOT</version>
</parent>

<artifactId>benchkit-backend</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver-parent</artifactId>
<version>5.25-SNAPSHOT</version>
<version>5.26-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver-parent</artifactId>
<version>5.25-SNAPSHOT</version>
<version>5.26-SNAPSHOT</version>
</parent>

<artifactId>neo4j-java-driver</artifactId>
Expand Down
21 changes: 18 additions & 3 deletions driver/src/main/java/org/neo4j/driver/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.stream.Stream;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.AsValue;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.InternalIsoDuration;
import org.neo4j.driver.internal.InternalPoint2D;
import org.neo4j.driver.internal.InternalPoint3D;
Expand Down Expand Up @@ -213,7 +214,14 @@ public static Value value(Object value) {
return value(Arrays.asList((Object[]) value));
}

throw new ClientException("Unable to convert " + value.getClass().getName() + " to Neo4j Value.");
var message = "Unable to convert " + value.getClass().getName() + " to Neo4j Value.";
throw new ClientException(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
"N/A",
message,
GqlStatusError.DIAGNOSTIC_RECORD,
null);
}

/**
Expand Down Expand Up @@ -588,10 +596,17 @@ public static Value point(int srid, double x, double y, double z) {
*/
public static Value parameters(Object... keysAndValues) {
if (keysAndValues.length % 2 != 0) {
throw new ClientException("Parameters function requires an even number " + "of arguments, "
var message = "Parameters function requires an even number " + "of arguments, "
+ "alternating key and value. Arguments were: "
+ Arrays.toString(keysAndValues)
+ ".");
+ ".";
throw new ClientException(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
"N/A",
message,
GqlStatusError.DIAGNOSTIC_RECORD,
null);
}
HashMap<String, Value> map = newHashMapWithSize(keysAndValues.length / 2);
for (var i = 0; i < keysAndValues.length; i += 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.Serial;
import org.neo4j.driver.AuthTokenManager;
import org.neo4j.driver.internal.GqlStatusError;

/**
* The {@link org.neo4j.driver.AuthTokenManager} execution has lead to an unexpected result.
Expand All @@ -42,6 +43,12 @@ public class AuthTokenManagerExecutionException extends ClientException {
* @param cause the cause
*/
public AuthTokenManagerExecutionException(String message, Throwable cause) {
super(message, cause);
super(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
"N/A",
message,
GqlStatusError.DIAGNOSTIC_RECORD,
cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
* Failed to authenticate the driver to the server due to bad credentials provided.
Expand All @@ -34,7 +38,35 @@ public class AuthenticationException extends SecurityException {
* @param code the code
* @param message the message
*/
// for testing only
public AuthenticationException(String code, String message) {
super(code, message);
this(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
code,
message,
GqlStatusError.DIAGNOSTIC_RECORD,
null);
}

/**
* Creates a new instance.
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
* @param statusDescription the status description
* @param code the code
* @param message the message
* @param diagnosticRecord the diagnostic record
* @param cause the cause
* @since 5.26.0
*/
@Preview(name = "GQL-error")
public AuthenticationException(
String gqlStatus,
String statusDescription,
String code,
String message,
Map<String, Value> diagnosticRecord,
Throwable cause) {
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
* The authorization info maintained on the server has expired. The client should reconnect.
Expand All @@ -38,7 +42,35 @@ public class AuthorizationExpiredException extends SecurityException implements
* @param code the code
* @param message the message
*/
// for testing only
public AuthorizationExpiredException(String code, String message) {
super(code, message);
this(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
code,
message,
GqlStatusError.DIAGNOSTIC_RECORD,
null);
}

/**
* Creates a new instance.
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
* @param statusDescription the status description
* @param code the code
* @param message the message
* @param diagnosticRecord the diagnostic record
* @param cause the cause
* @since 5.26.0
*/
@Preview(name = "GQL-error")
public AuthorizationExpiredException(
String gqlStatus,
String statusDescription,
String code,
String message,
Map<String, Value> diagnosticRecord,
Throwable cause) {
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
* A <em>ClientException</em> indicates that the client has carried out an operation incorrectly.
Expand All @@ -31,25 +35,67 @@ public class ClientException extends Neo4jException {
* Creates a new instance.
* @param message the message
*/
// for testing only
public ClientException(String message) {
super(message);
this(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
"N/A",
message,
GqlStatusError.DIAGNOSTIC_RECORD,
null);
}

/**
* Creates a new instance.
* @param message the message
* @param cause the cause
*/
// for testing only
public ClientException(String message, Throwable cause) {
super(message, cause);
this(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
"N/A",
message,
GqlStatusError.DIAGNOSTIC_RECORD,
cause);
}

/**
* Creates a new instance.
* @param code the code
* @param message the message
*/
// for testing only
public ClientException(String code, String message) {
super(code, message);
this(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
code,
message,
GqlStatusError.DIAGNOSTIC_RECORD,
null);
}

/**
* Creates a new instance.
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
* @param statusDescription the status description
* @param code the code
* @param message the message
* @param diagnosticRecord the diagnostic record
* @param cause the cause
* @since 5.26.0
*/
@Preview(name = "GQL-error")
public ClientException(
String gqlStatus,
String statusDescription,
String code,
String message,
Map<String, Value> diagnosticRecord,
Throwable cause) {
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
* A <em>DatabaseException</em> indicates that there is a problem within the underlying database.
Expand All @@ -32,7 +36,35 @@ public class DatabaseException extends Neo4jException {
* @param code the code
* @param message the message
*/
// for testing only
public DatabaseException(String code, String message) {
super(code, message);
this(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
code,
message,
GqlStatusError.DIAGNOSTIC_RECORD,
null);
}

/**
* Creates a new instance.
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
* @param statusDescription the status description
* @param code the code
* @param message the message
* @param diagnosticRecord the diagnostic record
* @param cause the cause
* @since 5.26.0
*/
@Preview(name = "GQL-error")
public DatabaseException(
String gqlStatus,
String statusDescription,
String code,
String message,
Map<String, Value> diagnosticRecord,
Throwable cause) {
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import org.neo4j.driver.internal.GqlStatusError;

/**
* An error has happened while getting routing table with a remote server.
Expand All @@ -36,6 +37,12 @@ public class DiscoveryException extends Neo4jException {
* @param cause the cause
*/
public DiscoveryException(String message, Throwable cause) {
super(message, cause);
super(
GqlStatusError.UNKNOWN.getStatus(),
GqlStatusError.UNKNOWN.getStatusDescription(message),
"N/A",
message,
GqlStatusError.DIAGNOSTIC_RECORD,
cause);
}
}
Loading

0 comments on commit 345503b

Please sign in to comment.