Skip to content
Open
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
48 changes: 44 additions & 4 deletions docs/modules/ROOT/pages/how-to/errors.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ A code that the table does not know is not an empty answer: `e.code` is `unknown

== The codes

One row for each code. A row with more than one engine exception matches any of them. The engine exception is matched by its Java class name. A failure that the Python layer raises itself, or that one package words differently, is matched by its text, after the rows that match a class. The first row that matches decides.
Each row gives one hint, and a code that has more than one cause has a row for each. A row with more than one engine exception matches any of them. The engine exception is matched by its Java class name, exactly: a subclass of a listed class is named in a row of its own, or stays `unknown` for a reason that `tests/test_error_codes_subclasses.py` records. A failure that the Python layer raises itself, or that one package words differently, is matched by its text, after the rows that match a class. The first row that matches decides.

[cols="2,2,3,5"]
|===
Expand Down Expand Up @@ -116,7 +116,7 @@ One row for each code. A row with more than one engine exception matches any of

| `database_exists`
| `DatabaseExistsError`
| `DatabaseOperationException`
| `DatabaseOperationException`, `DatabaseAlreadyExistsException`
| A database already exists at this path: open it with `open_database(path)`, or choose another path.

| `database_not_found`
Expand All @@ -129,6 +129,11 @@ One row for each code. A row with more than one engine exception matches any of
| `DatabaseIsClosedException`
| The database was closed: open it again with `open_database(path)`, and read what you need from a result before you close the database.

| `database_closed`
| `DatabaseClosedError`
| `DatabaseIsReopeningException`
| The database is being reopened (a replica installing a snapshot, for example): wait a moment, then open it again and repeat the call.

| `database_read_only`
| `ArcadeDBError`
| `DatabaseIsReadOnlyException`
Expand All @@ -139,6 +144,16 @@ One row for each code. A row with more than one engine exception matches any of
| `CommandSQLParsingException`, `CommandParsingException`
| The statement does not parse: fix the token that the message points at (line and column), and check the keywords against the ArcadeDB SQL or openCypher syntax.

| `syntax_error`
| `QuerySyntaxError`
| `CommandSemanticException`, `NonBooleanPatternExpressionException`
| The statement parses but breaks a rule of the query language (an undefined variable, or a pattern where only a true or false value fits, for example): change what the message names.

| `syntax_error`
| `QuerySyntaxError`
| `FeatureNotImplementedException`
| The engine does not support this construct: write the statement another way (the message names the construct).

| `timeout`
| `QueryTimeoutError`
| `TimeoutException`, `PartialResultTimeoutException`
Expand All @@ -149,6 +164,16 @@ One row for each code. A row with more than one engine exception matches any of
| `ConcurrentModificationException`, `LockTimeoutException`, `NeedRetryException`
| Another transaction changed the same data first: run the whole transaction again, for example with `db.run_in_transaction(fn)`, which retries it.

| `conflict`
| `ConflictError`
| `RefusedBeforePublishingException`, `QuorumNotReachedException`, `ReplicationQueueFullException`, `ServerIsNotTheLeaderException`, `RetryLaterException`
| The server or its cluster cannot take the transaction now (the message says why): run the whole transaction again, on the leader node when this node is not the leader.

| `conflict`
| `ConflictError`
| `WALVersionGapException`
| A replicated or recovered change does not follow the page version stored here, so this copy of the database may be behind or damaged: check the server log before you run the transaction again.

| `type_not_found`
| `SchemaError`
| `SchemaException`
Expand All @@ -159,21 +184,36 @@ One row for each code. A row with more than one engine exception matches any of
| `AlreadyExistsException`, `TypeAlreadyExistsException`
| A type, property or index with this name already exists: choose another name, or add `IF NOT EXISTS` to the CREATE statement of a type or an index.

| `already_exists`
| `SchemaError`
| `EquivalentIndexException`
| An index or constraint on these properties exists already, perhaps under another name: use it (`SELECT FROM schema:indexes` lists the indexes), or add `IF NOT EXISTS` to the CREATE statement.

| `schema`
| `SchemaError`
| `SchemaException`
| `SchemaException`, `ConstraintDropFailedException`, `IndexDropFailedException`
| The schema does not allow this change: read the message, and compare it with the current schema (`SELECT FROM schema:types`).

| `type_mismatch`
| `ValidationError`
| `IllegalArgumentException`, `TypeMismatchException`
| A value does not fit the type of its property: send a value of the declared type (the message names the property and the type).

| `type_mismatch`
| `ValidationError`
| `Type$InconvertibleValueException`, `ValueOutOfRangeException`, `InvalidPropertyTypeException`
| A value cannot become the type it has to be (a wrong shape, a number out of range, or a map where a property cannot hold one): change the value that the message names.

| `validation`
| `ValidationError`
| `ValidationException`
| A property constraint (mandatory, not null, min, max, regexp or read-only) refused the record: change the value that the message names, or change the constraint in the schema.

| `validation`
| `ValidationError`
| `RecordVetoedException`
| A listener on the database vetoed this write: change the record so that the listener accepts it, or remove the listener.

| `query_not_idempotent`
| `ArcadeDBError`
| `QueryNotIdempotentException`
Expand All @@ -190,7 +230,7 @@ The causes without a subclass (`database_read_only`, `query_not_idempotent`, `mi

== Which error to retry

`ConflictError` is the one that a retry can fix: another transaction changed the same data first. Run the whole transaction again, or let `db.run_in_transaction(fn)` do it, as described on xref:how-to/transactions.adoc[Transactions] and xref:how-to/concurrency.adoc[Concurrency, processes and crashes]. A `DuplicateKeyError` is not a conflict: the same statement fails again until the value changes. A `PartialCommitError` is a conflict that a retry must not repeat.
`ConflictError` is the one that a retry can fix: another transaction changed the same data first, or the server or its cluster could not take the transaction (the hint says which, and a WAL version gap needs a look at the server log first). Run the whole transaction again, or let `db.run_in_transaction(fn)` do it, as described on xref:how-to/transactions.adoc[Transactions] and xref:how-to/concurrency.adoc[Concurrency, processes and crashes]. A `DuplicateKeyError` is not a conflict: the same statement fails again until the value changes. A `PartialCommitError` is a conflict that a retry must not repeat.

[[partial-commit]]
== A block that already committed part of its work
Expand Down
84 changes: 81 additions & 3 deletions src/arcadedb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class _Rule(NamedTuple):


_E = "com.arcadedb.exception."
_CYPHER = "com.arcadedb.query.opencypher.parser."

_HINT_RECORD_NOT_FOUND = (
"No record has this RID: check the RID, or look the record up by a property with a query "
Expand All @@ -393,6 +394,8 @@ class _Rule(NamedTuple):
# The table that decides the class, the code and the hint of every error. The Java names and the texts are the ones the engine
# produces, collected by running both builds (tests/test_error_codes_table.py holds a literal for every row). A row with a
# ``message`` and no ``java`` is for a failure that the Python layer raises itself or that one build words differently.
# Class names are compared exactly, so a subclass of a listed class needs its own name here, or a reason to stay unknown in
# tests/test_error_codes_subclasses.py, which fails on an engine subclass that has neither (#507).
_RULES = (
# first: the engine wraps this refusal in a timeout when a COMMIT RETRY block ran out of time, and the half that is committed
# matters more than the deadline
Expand Down Expand Up @@ -436,7 +439,10 @@ class _Rule(NamedTuple):
"database_exists",
DatabaseExistsError,
"A database already exists at this path: open it with `open_database(path)`, or choose another path.",
java=(_E + "DatabaseOperationException",),
java=(
_E + "DatabaseOperationException",
"com.arcadedb.server.DatabaseAlreadyExistsException",
),
message=re.compile(r"already exists"),
),
_Rule(
Expand All @@ -451,6 +457,13 @@ class _Rule(NamedTuple):
_HINT_DATABASE_CLOSED,
java=(_E + "DatabaseIsClosedException",),
),
_Rule(
"database_closed",
DatabaseClosedError,
"The database is being reopened (a replica installing a snapshot, for example): wait a moment, then open it again "
"and repeat the call.",
java=(_E + "DatabaseIsReopeningException",),
),
_Rule(
"database_read_only",
ArcadeDBError,
Expand All @@ -464,6 +477,22 @@ class _Rule(NamedTuple):
"check the keywords against the ArcadeDB SQL or openCypher syntax.",
java=(_E + "CommandSQLParsingException", _E + "CommandParsingException"),
),
_Rule(
"syntax_error",
QuerySyntaxError,
"The statement parses but breaks a rule of the query language (an undefined variable, or a pattern where only a true "
"or false value fits, for example): change what the message names.",
java=(
_E + "CommandSemanticException",
_CYPHER + "NonBooleanPatternExpressionException",
),
),
_Rule(
"syntax_error",
QuerySyntaxError,
"The engine does not support this construct: write the statement another way (the message names the construct).",
java=(_CYPHER + "FeatureNotImplementedException",),
),
_Rule(
"timeout",
QueryTimeoutError,
Expand All @@ -482,6 +511,26 @@ class _Rule(NamedTuple):
_E + "NeedRetryException",
),
),
_Rule(
"conflict",
ConflictError,
"The server or its cluster cannot take the transaction now (the message says why): run the whole transaction again, on "
"the leader node when this node is not the leader.",
java=(
"com.arcadedb.database.RefusedBeforePublishingException",
"com.arcadedb.network.binary.QuorumNotReachedException",
"com.arcadedb.network.binary.ReplicationQueueFullException",
"com.arcadedb.network.binary.ServerIsNotTheLeaderException",
"com.arcadedb.server.http.RetryLaterException",
),
),
_Rule(
"conflict",
ConflictError,
"A replicated or recovered change does not follow the page version stored here, so this copy of the database may be "
"behind or damaged: check the server log before you run the transaction again.",
java=(_E + "WALVersionGapException",),
),
_Rule(
"type_not_found",
SchemaError,
Expand All @@ -496,11 +545,22 @@ class _Rule(NamedTuple):
"`IF NOT EXISTS` to the CREATE statement of a type or an index.",
java=(_E + "AlreadyExistsException", _E + "TypeAlreadyExistsException"),
),
_Rule(
"already_exists",
SchemaError,
"An index or constraint on these properties exists already, perhaps under another name: use it (`SELECT FROM "
"schema:indexes` lists the indexes), or add `IF NOT EXISTS` to the CREATE statement.",
java=(_E + "EquivalentIndexException",),
),
_Rule(
"schema",
SchemaError,
_HINT_SCHEMA,
java=(_E + "SchemaException",),
java=(
_E + "SchemaException",
_E + "ConstraintDropFailedException",
_E + "IndexDropFailedException",
),
),
_Rule(
"type_mismatch",
Expand All @@ -510,13 +570,31 @@ class _Rule(NamedTuple):
java=("java.lang.IllegalArgumentException", _E + "TypeMismatchException"),
message=re.compile(r"Cannot convert type"),
),
_Rule(
"type_mismatch",
ValidationError,
"A value cannot become the type it has to be (a wrong shape, a number out of range, or a map where a property cannot "
"hold one): change the value that the message names.",
java=(
"com.arcadedb.schema.Type$InconvertibleValueException",
_E + "ValueOutOfRangeException",
_E + "InvalidPropertyTypeException",
),
),
_Rule(
"validation",
ValidationError,
"A property constraint (mandatory, not null, min, max, regexp or read-only) refused the record: "
"change the value that the message names, or change the constraint in the schema.",
java=(_E + "ValidationException",),
),
_Rule(
"validation",
ValidationError,
"A listener on the database vetoed this write: change the record so that the listener accepts it, or remove the "
"listener.",
java=(_E + "RecordVetoedException",),
),
_Rule(
"query_not_idempotent",
ArcadeDBError,
Expand Down Expand Up @@ -579,7 +657,7 @@ def _partial_commit_error(block, conflict):
"""
chain = _java_chain_of(conflict)
if chain:
conflicts = _RULE_OF_CODE["conflict"].java
conflicts = {n for r in _RULES if r.code == "conflict" for n in r.java}
name, message = next(
(link for link in chain if link[0] in conflicts), chain[-1]
)
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"test_jvm_windows_avx512.py": "JVM arguments of Windows hosts with AVX-512",
"test_jar_provenance.py": "jar fingerprint of the JVM wheel",
"test_jar_closure.py": "jar closure of the JVM wheel",
"test_error_codes_subclasses.py": "the exception classes in the engine jars of the JVM wheel",
"test_java_package_shadowing.py": "JPype package import hooks",
"test_jpype_bare_exceptions.py": "the installed JPype of the JVM wheel",
"test_wheel_platform_tag.py": "JVM wheel tag",
Expand Down
22 changes: 22 additions & 0 deletions tests/test_error_codes_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ def unknown_property_type(db):
db.command("sql", "CREATE PROPERTY T.z FOOBAR")


def undefined_cypher_variable(db):
db.query("opencypher", "MATCH (n:V) RETURN nothere").to_list()


def list_for_an_integer(db):
with db.transaction():
db.command("sql", "INSERT INTO T SET id = [1, 2]")


def division_by_zero(db):
db.query("sql", "SELECT 1/0 AS x").to_list()

Expand Down Expand Up @@ -522,6 +531,19 @@ def unknown_function(db):
"missing_parameter",
E + "CommandParameterMissingException",
),
# a subclass of a listed class has its own row (#507)
(
on_a_database(undefined_cypher_variable),
"QuerySyntaxError",
"syntax_error",
E + "CommandSemanticException",
),
(
on_a_database(list_for_an_integer),
"ValidationError",
"type_mismatch",
"com.arcadedb.schema.Type$InconvertibleValueException",
),
# failures that the table does not know stay ArcadeDBError with the code unknown, with the same text as before
(
on_a_database(unknown_query_language),
Expand Down
Loading
Loading