Repository navigation
Errors carry a code, a hint and the Java cause, with a subclass for each common cause - #483
Merged
Merged
Conversation
…ach common cause (closes #475) An ArcadeDBError had one class and a Java text, so a program, or a model that writes the program, could only tell a duplicate key from a syntax error by searching the message. It now has `code`, `hint`, `cause` and `to_dict()`, and a subclass for duplicate key, record not found, transaction state, database exists, not found, locked and closed, syntax error, timeout, conflict, schema and validation. ArcadeDBError stays the base class. One table (`_RULES` in exceptions.py) decides the class, the code and the hint: a Java class name, an optional message pattern, the code, the class, the hint. `ArcadeDBError(text)` classifies in `__new__` from the Java exception being handled, or from the class names in the text, so the 165 raise sites are unchanged. The native build classifies the chain of the reply (`_native/database.py`, `_native/extras.py`), so both builds give the same class and code. A failure that no row knows stays ArcadeDBError with code "unknown" and keeps its text. The text of a classified error is `[code] hint` followed by the old text. Two places that compared the text exactly changed: the import page (`startswith` became `in`) and test_native_tx_crossings (`==` became `endswith` plus the code). New page how-to/errors.adoc with the table and the agent recipe. Tests: a literal per row of the table, 42 live failures on both builds with one set of literals, the blocks of the new page.
Collaborator
Author
|
Merged, and moved from 27.1.1 to 26.12.1. I merged it into |
This was referenced Nov 24, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
An
ArcadeDBErrornow says what went wrong and what to do next, in a form a program (or a model that writes the program) can read. It hascode(a short stable name, such asduplicate_key),hint(one sentence),cause(the Java exception class that decided the code) andto_dict(), and there is a subclass for each cause a program is likely to branch on.ArcadeDBErrorstays the base class, so everyexcept ArcadeDBErrorkeeps working.The class and the code come from one table,
_RULESinsrc/arcadedb/exceptions.py. A row is a Java class name, an optional message pattern, the code, the class and the hint.ArcadeDBError(text)picks the class itself from the Java exception being handled (or, with none, from the class names and wording in the text), so none of the 165 raise sites changed. The native build builds its errors from the chain of the reply (_native/database.pyand_native/extras.py, 3 lines each), so both builds use the same table. A failure that no row knows staysArcadeDBErrorwithcode = "unknown"and prints exactly the text it printed before.The codes and classes (hints are on the new page
how-to/errors.adoc):duplicate_keyDuplicateKeyErrorrecord_not_foundRecordNotFoundErrortransaction_not_begunTransactionErrordatabase_existsDatabaseExistsErrordatabase_not_foundDatabaseNotFoundErrordatabase_lockedDatabaseLockedErrordatabase_closedDatabaseClosedErrorsyntax_errorQuerySyntaxErrortimeoutQueryTimeoutErrorconflictConflictErrortype_not_found,already_exists,schemaSchemaErrorvalidation,type_mismatchValidationErrordatabase_read_only,query_not_idempotent,missing_parameterArcadeDBError(code only)I collected the Java classes and texts by running a probe of 54 cases on both wheels (26.12.1.dev0, JVM and native); the literals are in the tests.
Where I deviated from the design, and why
str(error)of a classified error is[code] hintfollowed by the old text, so the Java class and message stay at its end. An unknown error keeps its text unchanged. This is the one visible change for existing code: a program that comparesstr(e)for equality, or that checksstartswith, sees the new head. Searches ("Transaction not begun" in str(e),pytest.raises(..., match=...)) still work.e.argsis unchanged. Three docs places changed for this reason: the printed output of the quickstart and of databases and queries, and onestartswithof the import page (nowin). One existing test,test_native_tx_crossings.py, pinned the exact text and now checks the tail and the code.com.arcadedb.exceptionin the 26.12.1 snapshot for an SQLSTATE or an error code and found none). Its newErrorCategoryenum is for the server's status codes and the native library does not expose it, so I did not build on it.QuerySyntaxErrorandQueryTimeoutError, notSyntaxErrorandTimeoutError, so they do not shadow the builtins.database_read_only,query_not_idempotentandmissing_parameterhave a code and a hint but no subclass: a program rarely branches on them, and a subclass later is additive.hintisNoneforunknown, not a filler sentence.sys.exc_info()inArcadeDBError.__new__, which is what makes the 165 raise sites work unchanged. The alternative is an explicit factory at each site. If you prefer that, the table and the tests stay as they are.The hint for
transaction_not_begunand #479The hint is "No transaction is open: wrap the write in
with db.transaction():, or calldb.set_auto_transaction(True)so that each statement commits on its own." It is true with auto-transaction off (today) and on (#479): with it on, the error only comes fromcommit()with nothing open or fromset_auto_transaction(False), and both fixes still apply. The two PRs touch the same output line ofquickstart.adoc; whichever merges second needs a one-line rebase.What differs between the builds
The class and code are the same on both builds for all 42 live scenarios in
tests/test_error_codes_parity.py(one set of literals, no branch on the backend). Three failures differ in what is below the code:DROP PROPERTYandDROP INDEXof a missing name: the JVM engine throwsSchemaException, the native oneCommandExecutionExceptionwith the same message. A text row catches both, so the code isschemaon both andcausediffers.UnknownFunctionExceptionon the JVM,CommandExecutionExceptionon native. Both areunknown, andcausediffers.lookup_by_ridof a missing record: the JVM raises the engine'sRecordNotFoundException, the native Python layer raises its own "record not found". Both areRecordNotFoundError;causeisNoneon native.java_chainandnativestay on the native build only.Related issues
Closes #475
Docs
New page
how-to/errors.adoc(in the nav after Transactions): the attributes, the agent recipe (except ArcadeDBError as e: e.code, e.hint,e.to_dict()), the table of codes with class, engine exception and hint, which error to retry, and what differs between the packages.tests/test_docs_errors_page.pyruns its blocks andtest_error_codes_table.pychecks that every code, class and hint of the table is on the page. The outputs that print an error changed inquickstart.adocanddatabases-and-queries.adoc. The Antora build has no warning.Release note (draft)
Errors carry a stable code and a hint.
ArcadeDBErrorhascode,hint,causeandto_dict(), and the common causes are subclasses:DuplicateKeyError,RecordNotFoundError,TransactionError,DatabaseExistsError,DatabaseNotFoundError,DatabaseLockedError,DatabaseClosedError,QuerySyntaxError,QueryTimeoutError,ConflictError,SchemaErrorandValidationError. Both packages give the same class and code for the same failure.except ArcadeDBErrorkeeps working. The text of a classified error now starts with[code] hintand ends with the old text; an error with the codeunknownprints exactly what it printed before. See the new page "Errors: codes, hints and classes".Milestone
27.1.1, not 26.12.1. The change is additive in the API, but it is about 1,900 lines (1,200 of them tests), it changes
str()of classified errors, and it touches the same docs lines as #479. That is more than I want in the 26.12.1 cut of 2 December. If you would rather have it there, the CI result below says whether the whole PR is green on both builds.Tests
tests/test_error_codes_table.py: a literal (Java chain and text) for every row of the table, a test that fails when a row has no literal, thestrandto_dictshape, hand-built subclasses, wrappers, pickle and copy.tests/test_error_codes_parity.py: 42 live failures asserted on both builds with one set of literals, plus a second process that holds the lock.tests/test_docs_errors_page.py: the blocks of the new page.mainwheels of 24 November with these Python files over them: the whole suite on the JVM wheel (4191 passed, 2 warnings) and on the native wheel (1 failed, 4242 passed, 117 skipped, 3 warnings; the skips are the counted NOTYET and NA-JVM kinds). The one native failure,test_native_tx_crossings.py::test_a_commit_without_begin_raises_the_engines_error_unchanged, pinned the exact text and is changed in this PR (endswithplus the code); I reran it and the new files on the native wheel afterwards (154 passed). CI builds its own wheels and runs the parity jobs.Checklist
uvx pre-commit run --files <changed files>passes