You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: go-manual/modules/ROOT/pages/query-simple.adoc
+88-6Lines changed: 88 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -189,17 +189,18 @@ For those rare use cases, see xref:query-advanced#_dynamic_values_in_property_ke
189
189
190
190
A query run may fail for a number of reasons.
191
191
When using `ExecuteQuery()`, the driver automatically retries to run a failed query if the failure is deemed to be transient (for example due to temporary server unavailability).
192
-
An error will be raised if the operation keeps failing after the configured link:https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/neo4j/config#Config.MaxTransactionRetryTime[maximum retry time].
193
192
194
-
All link:https://neo4j.com/docs/status-codes/current/errors/all-errors/[errors coming from the server] are of type link:https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/neo4j#Neo4jError[`Neo4jError`].
195
-
You can use an error's code to stably identify a specific error; error messages are instead not stable markers, and should not be relied upon.
193
+
An error is raised if the operation keeps failing after a number of attempts.
194
+
195
+
All errors coming from the server are of type link:https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/neo4j#Neo4jError[`Neo4jError`].
196
+
You can use an exception's code to stably identify a specific error; error messages are instead not stable markers, and should not be relied upon.
@@ -218,6 +219,87 @@ Error message: Invalid input '': expected an expression, '*', 'ALL' or 'DISTINCT
218
219
*/
219
220
----
220
221
222
+
Exception objects also expose errors as GQL-status objects.
223
+
The main difference between link:https://neo4j.com/docs/status-codes/current/errors/all-errors/[Neo4j error codes] and link:https://neo4j.com/docs/status-codes/current/errors/gql-errors/[GQL error codes] is that the GQL ones are more granular: a single Neo4j error code might be broken in several, more specific GQL error codes.
224
+
225
+
The actual _cause_ that triggered an exception is sometimes found in the optional GQL-status object `.GqlCause`, which is itself a `Neo4jError`.
226
+
You might need to recursively traverse the cause chain before reaching the root cause of the exception you caught.
227
+
In the example below, the exception's GQL status code is `42001`, but the actual source of the error has status code `42I06`.
Error GQL cause: Neo4jError: Neo.DatabaseError.General.UnknownError (42I06: Invalid input '', expected: an expression, '*', 'ALL' or 'DISTINCT'.)
258
+
*/
259
+
----
260
+
261
+
GQL status codes are particularly helpful when you want your application to behave differently depending on the exact error that was raised by the server.
# special handling of user not having CREATE permissions
279
+
fmt.Println(neo4jErr.Error())
280
+
} else {
281
+
# handling of all other exceptions
282
+
fmt.Println(neo4jErr.Error())
283
+
}
284
+
}
285
+
}
286
+
----
287
+
288
+
[NOTE]
289
+
====
290
+
The GQL status code `50N42` is returned when an error does not have a GQL-status object.
291
+
This can happen if the driver is connected to an older Neo4j server.
292
+
Don't rely on this status code, as future Neo4j server versions might change it with a more appropriate one.
293
+
====
294
+
295
+
[TIP]
296
+
====
297
+
Transient server errors can be retried without need to alter the original request.
298
+
You can discover whether an error is transient via the function link:https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/neo4j#IsRetryable[`neo4j.IsRetryable(error)`], which gives insights into whether a further attempt might be successful.
299
+
This is particular useful when running queries in xref:transactions#explicit-transactions[explicit transactions], to know if a failed query is worth re-running.
Copy file name to clipboardExpand all lines: javascript-manual/modules/ROOT/pages/query-simple.adoc
+90-9Lines changed: 90 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,21 +147,21 @@ For those rare use cases, see xref:query-advanced#_dynamic_values_in_property_ke
147
147
== Error handling
148
148
149
149
A query run may fail for a number of reasons.
150
+
150
151
When using `driver.execute_query()`, the driver automatically retries to run a failed query if the failure is deemed to be transient (for example due to temporary server unavailability).
151
-
An error will be raised if the operation keeps failing after the configured link:https://neo4j.com/docs/api/javascript-driver/{javascript-driver-version}/class/lib6/types.js~Config.html#instance-member-maxTransactionRetryTime[maximum retry time].
152
+
An error will be raised if the operation keeps failing after the configured link:https://neo4j.com/docs/api/javascript-driver/current/class/lib6/types.js~Config.html#instance-member-maxTransactionRetryTime[maximum retry time].
152
153
153
-
All link:https://neo4j.com/docs/status-codes/current/errors/all-errors/[errors coming from the server] are subclasses of link:https://neo4j.com/docs/api/javascript-driver/{javascript-driver-version}/class/lib6/error.js~Neo4jError.html[`Neo4jError`].
154
+
All link:https://neo4j.com/docs/status-codes/current/errors/all-errors/[errors coming from the server] are subclasses of link:https://neo4j.com/docs/api/javascript-driver/current/class/lib6/error.js~Neo4jError.html[`Neo4jError`].
154
155
You can use an exception's code to stably identify a specific error; error messages are instead not stable markers, and should not be relied upon.
Error objects also expose errors as GQL-status objects.
178
+
The main difference between link:https://neo4j.com/docs/status-codes/current/errors/all-errors/[Neo4j error codes] and link:https://neo4j.com/docs/status-codes/current/errors/gql-errors/[GQL error codes] is that the GQL ones are more granular: a single Neo4j error code might be broken in several, more specific GQL error codes.
179
+
180
+
The actual _cause_ that triggered an error is sometimes found in the optional GQL-status object `.cause`, which is itself a `Neo4jError`.
181
+
You might need to recursively traverse the cause chain before reaching the root cause of the error you caught.
182
+
In the example below, the error's GQL status code is `42001`, but the actual source of the error has status code `42I06`.
183
+
184
+
.Usage of `Neo4jError` with GQL-related methods
185
+
[source, javascript]
186
+
----
187
+
let err = await driver.executeQuery(
188
+
'MATCH (p:Person) RETURN ',
189
+
{},
190
+
{ database: 'neo4j' }
191
+
)
192
+
} catch (err) {
193
+
console.log('Error GQL status:', err.gqlStatus)
194
+
console.log('Error GQL status description:', err.gqlStatusDescription)
Error GQL status description: error: syntax error or access rule violation - invalid syntax
202
+
Error GQL classification: CLIENT_ERROR
203
+
Error GQL cause: GQLError: 42I06: Invalid input '', expected: an expression, '*', 'ALL' or 'DISTINCT'.
204
+
Error GQL diagnostic record: {
205
+
OPERATION: '',
206
+
OPERATION_CODE: '0',
207
+
CURRENT_SCHEMA: '/',
208
+
_classification: 'CLIENT_ERROR',
209
+
_position: {
210
+
line: Integer { low: 1, high: 0 },
211
+
column: Integer { low: 25, high: 0 },
212
+
offset: Integer { low: 24, high: 0 }
213
+
}
214
+
}
215
+
*/
216
+
----
217
+
218
+
GQL status codes are particularly helpful when you want your application to behave differently depending on the exact error that was raised by the server.
219
+
220
+
.Distinguishing between different error codes
221
+
[source, javascript]
222
+
----
223
+
let err = await driver.executeQuery(
224
+
'MATCH (p:Person) RETURN ',
225
+
{},
226
+
{ database: 'neo4j' }
227
+
)
228
+
} catch (err) {
229
+
if hasGqlStatus(err, '42001') {
230
+
# Neo.ClientError.Statement.SyntaxError
231
+
# special handling of syntax error in query
232
+
console.log(err.message)
233
+
} else if hasGqlStatus(err, '42NFF') {
234
+
# Neo.ClientError.Security.Forbidden
235
+
# special handling of user not having CREATE permissions
236
+
console.log(err.message)
237
+
} else {
238
+
# handling of all other errors
239
+
console.log(err.message)
240
+
}
241
+
}
242
+
----
243
+
244
+
[NOTE]
245
+
====
246
+
The GQL status code `50N42` is returned when an error does not have a GQL-status object.
247
+
This can happen if the driver is connected to an older Neo4j server.
248
+
Don't rely on this status code, as future Neo4j server versions might change it with a more appropriate one.
249
+
====
250
+
251
+
[TIP]
252
+
====
253
+
Transient server errors can be retried without need to alter the original request.
254
+
You can discover whether an error is transient via the method `Neo4jError.isRetryable()`, which gives insights into whether a further attempt might be successful.
255
+
This is particular useful when running queries in xref:transactions#explicit-transactions[explicit transactions], to know if a failed query is worth re-running.
Copy file name to clipboardExpand all lines: python-manual/modules/ROOT/pages/query-simple.adoc
+73-4Lines changed: 73 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,22 +155,25 @@ There can be circumstances where your query structure prevents the usage of para
155
155
For those rare use cases, see xref:query-advanced#_dynamic_values_in_property_keys_relationship_types_and_labels[Dynamic values in property keys, relationship types, and labels].
156
156
157
157
158
+
159
+
[#error-handling]
158
160
== Error handling
159
161
160
162
A query run may fail for a number of reasons, with different link:https://neo4j.com/docs/api/python-driver/current/api.html#errors[exceptions] being raised.
161
163
When using `driver.execute_query()`, the driver automatically retries to run a failed query if the failure is deemed to be transient (for example due to temporary server unavailability).
162
-
An error will be raised if the operation keeps failing after the configured link:https://neo4j.com/docs/api/python-driver/current/api.html#max-transaction-retry-time[maximum retry time].
163
164
164
-
All link:https://neo4j.com/docs/status-codes/current/errors/all-errors/[exceptions coming from the server] are subclasses of link:https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.exceptions.Neo4jError[`Neo4jError`].
165
+
An exception will be raised if the operation keeps failing after a number of attempts.
166
+
167
+
All exceptions coming from the server are subclasses of link:https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.exceptions.Neo4jError[`Neo4jError`].
165
168
You can use an exception's code to stably identify a specific error; error messages are instead not stable markers, and should not be relied upon.
@@ -182,6 +185,72 @@ Exception message: Invalid input '': expected an expression, '*', 'ALL' or 'DIST
182
185
'''
183
186
----
184
187
188
+
Exception objects also expose errors as GQL-status objects.
189
+
The main difference between link:https://neo4j.com/docs/status-codes/current/errors/all-errors/[Neo4j error codes] and link:https://neo4j.com/docs/status-codes/current/errors/gql-errors/[GQL error codes] is that the GQL ones are more granular: a single Neo4j error code might be broken in several, more specific GQL error codes.
190
+
191
+
The actual _cause_ that triggered an exception is sometimes found in the optional GQL-status object `\\__cause__`, which is itself a `Neo4jError`.
192
+
You might need to recursively traverse the cause chain before reaching the root cause of the exception you caught.
193
+
In the example below, the exception's GQL status code is `42001`, but the actual source of the error has status code `42I06`.
GQL status codes are particularly helpful when you want your application to behave differently depending on the exact error that was raised by the server.
# special handling of user not having CREATE permissions
234
+
print(e.message)
235
+
else:
236
+
# handling of all other exceptions
237
+
print(e.message)
238
+
----
239
+
240
+
[NOTE]
241
+
====
242
+
The GQL status code `50N42` is returned when an exception does not have a GQL-status object.
243
+
This can happen if the driver is connected to an older Neo4j server.
244
+
Don't rely on this status code, as future Neo4j server versions might change it with a more appropriate one.
245
+
====
246
+
247
+
[TIP]
248
+
====
249
+
Transient server errors can be retried without need to alter the original request.
250
+
You can discover whether an error is transient via the method `Neo4jError.is_retryable()`, which gives insights into whether a further attempt might be successful.
251
+
This is particular useful when running queries in xref:transactions#explicit-transactions[explicit transactions], to know if a failed query is worth re-running.
0 commit comments