Errors: codes, hints and classes
Every failed call raises ArcadeDBError. The error carries what a program needs to repair the call, so it does not have to search the message text:
-
e.codeis a short, stable name of the cause, for exampleduplicate_key. A failure that the table below does not know has the codeunknown. -
e.hintis one sentence that tells what to do next. It isNoneforunknown. -
e.causeis the name of the Java exception class that decided the code, for examplecom.arcadedb.exception.DuplicatedKeyException. It isNonewhen no Java exception is involved. -
e.to_dict()returnstype(the class name),code,hint,causeandmessage(the text without the code and the hint) as plain data, for a log or for the next prompt of a model.
The common causes have a subclass of ArcadeDBError, so except DuplicateKeyError works and every except ArcadeDBError in existing code still catches everything. The engine does not give an error code of its own, so the code names are the ones of the bindings. They are the same in both packages: the same failure gives the same class and code in arcadedb (native) and in arcadedb-jvm.
Repair a call from its error
The blocks on this page run one after the other against one empty database, and a test in the repository runs them that way (tests/test_docs_errors_page.py). Every block assumes that db is an open database.
from arcadedb import ArcadeDBError, DuplicateKeyError
db.command("sql", "CREATE DOCUMENT TYPE Memory")
db.command("sql", "CREATE PROPERTY Memory.key STRING")
db.command("sql", "CREATE INDEX ON Memory (key) UNIQUE")
with db.transaction():
db.command("sql", "INSERT INTO Memory SET key = 'a'")
try:
with db.transaction():
db.command("sql", "INSERT INTO Memory SET key = 'a'")
except DuplicateKeyError as e:
print(e.code)
print(e.hint)
duplicate_key
A unique index already holds this key: use another value, or update the record that has it (the message names the index and the record).
str(e) of a classified error is [code] hint followed by the text that the error had before, so the Java class and its message stay at the end and code that searches the text still finds them. An error with the code unknown prints exactly the older text.
try:
db.query("sql", "SELECT FROM Nope")
except ArcadeDBError as e:
print(type(e).__name__, e.code, e.cause)
print(e)
SchemaError type_not_found com.arcadedb.exception.SchemaException
[type_not_found] No type has this name: check the spelling against `SELECT name FROM schema:types`, or create the type first with `CREATE DOCUMENT TYPE`, `CREATE VERTEX TYPE` or `CREATE EDGE TYPE`. Query failed: com.arcadedb.exception.SchemaException: Type with name 'Nope' was not found
A program that runs statements for a model returns the error as data, and the model reads the code and the hint:
def run(statement):
try:
return {"ok": True, "rows": db.command("sql", statement).to_list()}
except ArcadeDBError as e:
return {"ok": False, "error": e.to_dict()}
reply = run("SELEC FROM Memory")
print(reply["ok"], reply["error"]["type"], reply["error"]["code"])
print(sorted(reply["error"]))
False QuerySyntaxError syntax_error
['cause', 'code', 'hint', 'message', 'type']
A code that the table does not know is not an empty answer: e.code is unknown, e.cause names the innermost Java exception when there is one, and the message is the engine’s text.
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.
| Code | Class | Engine exception | Hint |
|---|---|---|---|
|
|
|
A unique index already holds this key: use another value, or update the record that has it (the message names the index and the record). |
|
|
|
No record has this RID: check the RID, or look the record up by a property with a query (it may have been deleted, or it was never committed). |
|
|
|
No transaction is open: wrap the write in |
|
|
|
Another process has this database open: close it there first, because only one process can open a database at a time. |
|
|
|
A database already exists at this path: open it with |
|
|
|
No database exists at this path: check the path, or create one with |
|
|
|
The database was closed: open it again with |
|
|
|
The database was opened with |
|
|
|
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. |
|
|
|
The statement ran past its TIMEOUT clause: add a filter, a LIMIT or an index so that it finishes sooner, or raise the timeout. |
|
|
|
Another transaction changed the same data first: run the whole transaction again, for example with |
|
|
|
No type has this name: check the spelling against |
|
|
|
A type, property or index with this name already exists: choose another name, or add |
|
|
|
The schema does not allow this change: read the message, and compare it with the current schema ( |
|
|
|
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). |
|
|
|
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. |
|
|
|
|
|
|
|
The statement has a parameter that was not passed: give a value for each |
The causes without a subclass (database_read_only, query_not_idempotent, missing_parameter) raise ArcadeDBError itself, with the code set. Branch on e.code for them.
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 Transactions and Concurrency, processes and crashes. A DuplicateKeyError is not a conflict: the same statement fails again until the value changes.
What differs between the packages
Nothing in code, hint and the class. The native package also keeps e.java_chain (the chain of Java exceptions as (class, message) pairs) and e.native (the reply of the library), which the JVM package does not have; e.cause is the same name on both. Where the two engines word a failure differently, the table has a row for each wording, and a test runs every row against both packages.