Skip to content

Commit cf77036

Browse files
committed
Add preview support for GQL Errors
This update brings initial support for GQL Errors.
1 parent 5c9a7c2 commit cf77036

File tree

78 files changed

+2844
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2844
-166
lines changed

driver/src/main/java/org/neo4j/driver/Values.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.stream.Stream;
4141
import org.neo4j.driver.exceptions.ClientException;
4242
import org.neo4j.driver.internal.AsValue;
43+
import org.neo4j.driver.internal.GqlStatusError;
4344
import org.neo4j.driver.internal.InternalIsoDuration;
4445
import org.neo4j.driver.internal.InternalPoint2D;
4546
import org.neo4j.driver.internal.InternalPoint3D;
@@ -213,7 +214,14 @@ public static Value value(Object value) {
213214
return value(Arrays.asList((Object[]) value));
214215
}
215216

216-
throw new ClientException("Unable to convert " + value.getClass().getName() + " to Neo4j Value.");
217+
var message = "Unable to convert " + value.getClass().getName() + " to Neo4j Value.";
218+
throw new ClientException(
219+
GqlStatusError.UNKNOWN.getStatus(),
220+
GqlStatusError.UNKNOWN.getStatusDescription(message),
221+
"N/A",
222+
message,
223+
GqlStatusError.DIAGNOSTIC_RECORD,
224+
null);
217225
}
218226

219227
/**
@@ -588,10 +596,17 @@ public static Value point(int srid, double x, double y, double z) {
588596
*/
589597
public static Value parameters(Object... keysAndValues) {
590598
if (keysAndValues.length % 2 != 0) {
591-
throw new ClientException("Parameters function requires an even number " + "of arguments, "
599+
var message = "Parameters function requires an even number " + "of arguments, "
592600
+ "alternating key and value. Arguments were: "
593601
+ Arrays.toString(keysAndValues)
594-
+ ".");
602+
+ ".";
603+
throw new ClientException(
604+
GqlStatusError.UNKNOWN.getStatus(),
605+
GqlStatusError.UNKNOWN.getStatusDescription(message),
606+
"N/A",
607+
message,
608+
GqlStatusError.DIAGNOSTIC_RECORD,
609+
null);
595610
}
596611
HashMap<String, Value> map = newHashMapWithSize(keysAndValues.length / 2);
597612
for (var i = 0; i < keysAndValues.length; i += 2) {

driver/src/main/java/org/neo4j/driver/exceptions/AuthTokenManagerExecutionException.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.Serial;
2020
import org.neo4j.driver.AuthTokenManager;
21+
import org.neo4j.driver.internal.GqlStatusError;
2122

2223
/**
2324
* The {@link org.neo4j.driver.AuthTokenManager} execution has lead to an unexpected result.
@@ -42,6 +43,12 @@ public class AuthTokenManagerExecutionException extends ClientException {
4243
* @param cause the cause
4344
*/
4445
public AuthTokenManagerExecutionException(String message, Throwable cause) {
45-
super(message, cause);
46+
super(
47+
GqlStatusError.UNKNOWN.getStatus(),
48+
GqlStatusError.UNKNOWN.getStatusDescription(message),
49+
"N/A",
50+
message,
51+
GqlStatusError.DIAGNOSTIC_RECORD,
52+
cause);
4653
}
4754
}

driver/src/main/java/org/neo4j/driver/exceptions/AuthenticationException.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
package org.neo4j.driver.exceptions;
1818

1919
import java.io.Serial;
20+
import java.util.Map;
21+
import org.neo4j.driver.Value;
22+
import org.neo4j.driver.internal.GqlStatusError;
23+
import org.neo4j.driver.util.Preview;
2024

2125
/**
2226
* Failed to authenticate the driver to the server due to bad credentials provided.
@@ -34,7 +38,35 @@ public class AuthenticationException extends SecurityException {
3438
* @param code the code
3539
* @param message the message
3640
*/
41+
// for testing only
3742
public AuthenticationException(String code, String message) {
38-
super(code, message);
43+
this(
44+
GqlStatusError.UNKNOWN.getStatus(),
45+
GqlStatusError.UNKNOWN.getStatusDescription(message),
46+
code,
47+
message,
48+
GqlStatusError.DIAGNOSTIC_RECORD,
49+
null);
50+
}
51+
52+
/**
53+
* Creates a new instance.
54+
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
55+
* @param statusDescription the status description
56+
* @param code the code
57+
* @param message the message
58+
* @param diagnosticRecord the diagnostic record
59+
* @param cause the cause
60+
* @since 5.26.0
61+
*/
62+
@Preview(name = "GQL-error")
63+
public AuthenticationException(
64+
String gqlStatus,
65+
String statusDescription,
66+
String code,
67+
String message,
68+
Map<String, Value> diagnosticRecord,
69+
Throwable cause) {
70+
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
3971
}
4072
}

driver/src/main/java/org/neo4j/driver/exceptions/AuthorizationExpiredException.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
package org.neo4j.driver.exceptions;
1818

1919
import java.io.Serial;
20+
import java.util.Map;
21+
import org.neo4j.driver.Value;
22+
import org.neo4j.driver.internal.GqlStatusError;
23+
import org.neo4j.driver.util.Preview;
2024

2125
/**
2226
* The authorization info maintained on the server has expired. The client should reconnect.
@@ -38,7 +42,35 @@ public class AuthorizationExpiredException extends SecurityException implements
3842
* @param code the code
3943
* @param message the message
4044
*/
45+
// for testing only
4146
public AuthorizationExpiredException(String code, String message) {
42-
super(code, message);
47+
this(
48+
GqlStatusError.UNKNOWN.getStatus(),
49+
GqlStatusError.UNKNOWN.getStatusDescription(message),
50+
code,
51+
message,
52+
GqlStatusError.DIAGNOSTIC_RECORD,
53+
null);
54+
}
55+
56+
/**
57+
* Creates a new instance.
58+
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
59+
* @param statusDescription the status description
60+
* @param code the code
61+
* @param message the message
62+
* @param diagnosticRecord the diagnostic record
63+
* @param cause the cause
64+
* @since 5.26.0
65+
*/
66+
@Preview(name = "GQL-error")
67+
public AuthorizationExpiredException(
68+
String gqlStatus,
69+
String statusDescription,
70+
String code,
71+
String message,
72+
Map<String, Value> diagnosticRecord,
73+
Throwable cause) {
74+
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
4375
}
4476
}

driver/src/main/java/org/neo4j/driver/exceptions/ClientException.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
package org.neo4j.driver.exceptions;
1818

1919
import java.io.Serial;
20+
import java.util.Map;
21+
import org.neo4j.driver.Value;
22+
import org.neo4j.driver.internal.GqlStatusError;
23+
import org.neo4j.driver.util.Preview;
2024

2125
/**
2226
* A <em>ClientException</em> indicates that the client has carried out an operation incorrectly.
@@ -31,25 +35,67 @@ public class ClientException extends Neo4jException {
3135
* Creates a new instance.
3236
* @param message the message
3337
*/
38+
// for testing only
3439
public ClientException(String message) {
35-
super(message);
40+
this(
41+
GqlStatusError.UNKNOWN.getStatus(),
42+
GqlStatusError.UNKNOWN.getStatusDescription(message),
43+
"N/A",
44+
message,
45+
GqlStatusError.DIAGNOSTIC_RECORD,
46+
null);
3647
}
3748

3849
/**
3950
* Creates a new instance.
4051
* @param message the message
4152
* @param cause the cause
4253
*/
54+
// for testing only
4355
public ClientException(String message, Throwable cause) {
44-
super(message, cause);
56+
this(
57+
GqlStatusError.UNKNOWN.getStatus(),
58+
GqlStatusError.UNKNOWN.getStatusDescription(message),
59+
"N/A",
60+
message,
61+
GqlStatusError.DIAGNOSTIC_RECORD,
62+
cause);
4563
}
4664

4765
/**
4866
* Creates a new instance.
4967
* @param code the code
5068
* @param message the message
5169
*/
70+
// for testing only
5271
public ClientException(String code, String message) {
53-
super(code, message);
72+
this(
73+
GqlStatusError.UNKNOWN.getStatus(),
74+
GqlStatusError.UNKNOWN.getStatusDescription(message),
75+
code,
76+
message,
77+
GqlStatusError.DIAGNOSTIC_RECORD,
78+
null);
79+
}
80+
81+
/**
82+
* Creates a new instance.
83+
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
84+
* @param statusDescription the status description
85+
* @param code the code
86+
* @param message the message
87+
* @param diagnosticRecord the diagnostic record
88+
* @param cause the cause
89+
* @since 5.26.0
90+
*/
91+
@Preview(name = "GQL-error")
92+
public ClientException(
93+
String gqlStatus,
94+
String statusDescription,
95+
String code,
96+
String message,
97+
Map<String, Value> diagnosticRecord,
98+
Throwable cause) {
99+
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
54100
}
55101
}

driver/src/main/java/org/neo4j/driver/exceptions/DatabaseException.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
package org.neo4j.driver.exceptions;
1818

1919
import java.io.Serial;
20+
import java.util.Map;
21+
import org.neo4j.driver.Value;
22+
import org.neo4j.driver.internal.GqlStatusError;
23+
import org.neo4j.driver.util.Preview;
2024

2125
/**
2226
* A <em>DatabaseException</em> indicates that there is a problem within the underlying database.
@@ -32,7 +36,35 @@ public class DatabaseException extends Neo4jException {
3236
* @param code the code
3337
* @param message the message
3438
*/
39+
// for testing only
3540
public DatabaseException(String code, String message) {
36-
super(code, message);
41+
this(
42+
GqlStatusError.UNKNOWN.getStatus(),
43+
GqlStatusError.UNKNOWN.getStatusDescription(message),
44+
code,
45+
message,
46+
GqlStatusError.DIAGNOSTIC_RECORD,
47+
null);
48+
}
49+
50+
/**
51+
* Creates a new instance.
52+
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
53+
* @param statusDescription the status description
54+
* @param code the code
55+
* @param message the message
56+
* @param diagnosticRecord the diagnostic record
57+
* @param cause the cause
58+
* @since 5.26.0
59+
*/
60+
@Preview(name = "GQL-error")
61+
public DatabaseException(
62+
String gqlStatus,
63+
String statusDescription,
64+
String code,
65+
String message,
66+
Map<String, Value> diagnosticRecord,
67+
Throwable cause) {
68+
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
3769
}
3870
}

driver/src/main/java/org/neo4j/driver/exceptions/DiscoveryException.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.neo4j.driver.exceptions;
1818

1919
import java.io.Serial;
20+
import org.neo4j.driver.internal.GqlStatusError;
2021

2122
/**
2223
* An error has happened while getting routing table with a remote server.
@@ -36,6 +37,12 @@ public class DiscoveryException extends Neo4jException {
3637
* @param cause the cause
3738
*/
3839
public DiscoveryException(String message, Throwable cause) {
39-
super(message, cause);
40+
super(
41+
GqlStatusError.UNKNOWN.getStatus(),
42+
GqlStatusError.UNKNOWN.getStatusDescription(message),
43+
"N/A",
44+
message,
45+
GqlStatusError.DIAGNOSTIC_RECORD,
46+
cause);
4047
}
4148
}

driver/src/main/java/org/neo4j/driver/exceptions/FatalDiscoveryException.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
package org.neo4j.driver.exceptions;
1818

1919
import java.io.Serial;
20+
import java.util.Map;
21+
import org.neo4j.driver.Value;
22+
import org.neo4j.driver.internal.GqlStatusError;
23+
import org.neo4j.driver.util.Preview;
2024

2125
/**
2226
* This error indicate a fatal problem to obtain routing tables such as the routing table for a specified database does not exist.
@@ -31,16 +35,52 @@ public class FatalDiscoveryException extends ClientException {
3135
* Creates a new instance.
3236
* @param message the message
3337
*/
38+
// for testing only
3439
public FatalDiscoveryException(String message) {
35-
super(message);
40+
this(
41+
GqlStatusError.UNKNOWN.getStatus(),
42+
GqlStatusError.UNKNOWN.getStatusDescription(message),
43+
"N/A",
44+
message,
45+
GqlStatusError.DIAGNOSTIC_RECORD,
46+
null);
3647
}
3748

3849
/**
3950
* Creates a new instance.
4051
* @param code the code
4152
* @param message the message
4253
*/
54+
// for testing only
55+
@Deprecated
4356
public FatalDiscoveryException(String code, String message) {
44-
super(code, message);
57+
this(
58+
GqlStatusError.UNKNOWN.getStatus(),
59+
GqlStatusError.UNKNOWN.getStatusDescription(message),
60+
code,
61+
message,
62+
GqlStatusError.DIAGNOSTIC_RECORD,
63+
null);
64+
}
65+
66+
/**
67+
* Creates a new instance.
68+
* @param gqlStatus the GQLSTATUS as defined by the GQL standard
69+
* @param statusDescription the status description
70+
* @param code the code
71+
* @param message the message
72+
* @param diagnosticRecord the diagnostic record
73+
* @param cause the cause
74+
* @since 5.26.0
75+
*/
76+
@Preview(name = "GQL-error")
77+
public FatalDiscoveryException(
78+
String gqlStatus,
79+
String statusDescription,
80+
String code,
81+
String message,
82+
Map<String, Value> diagnosticRecord,
83+
Throwable cause) {
84+
super(gqlStatus, statusDescription, code, message, diagnosticRecord, cause);
4585
}
4686
}

0 commit comments

Comments
 (0)