Python

Errors

Usage guide and preserved examples for errors in Python.

The Python errors reference continues the Python overview.

Exception and value classes

ClassKindRole
MaelysDatalogErrorException classException carrying a native status and structured diagnostic.
DiagnosticImmutable value classImmutable native detail record, separate from the operation status.
StatusEnumerationNamed native operation statuses, used when handling exceptions.

Properties and attributes

Read properties without parentheses. Their links lead to the canonical class card.

Property / protocolTypeMeaning
error.statusintNative operation status; compare with Status members.
error.codeintAlias of error.status; not the diagnostic reason code.
error.messagestrHuman-readable detail.
error.hintstrSuggested corrective action when supplied.
error.diagnosticDiagnosticStructured native detail, including its distinct reason code and presence mask.

Usage and examples

Distinguish Python argument errors from native engine failures, then place both addition and solving inside an appropriate exception handler.

The detailed API gives the exact declarations; the sections below explain their use.

Python exceptions

The following built-in exceptions are not additional binding classes. Their links explain the rejected input or lifecycle operation.

ExceptionMeaning
TypeErrorWrong Python representation.
ValueErrorInvalid value or embedded NUL.
OverflowErrorInteger outside signed 64-bit range.
RuntimeErrorLifecycle misuse; also the superclass of MaelysDatalogError.

Shape errors and native errors

An input can fail in two very different ways, from two different layers: a wrongly shaped Python call, or a well-shaped fact that the engine rejects. They raise different exception types, and they occur at different times in Python.

Shape errors — Python exceptions

Before buffering a fact, the wrapper checks its Python representation. It also validates query and enumeration arguments before passing them to C:

Input errorWhere checkedRaises
Predicate name is not a nonempty stringAddition/query/enumerationTypeError
terms is not a sequence, or is itself str/bytesAddition/queryTypeError
Unsupported term such as float or a legacy TermAddition/queryTypeError
Embedded NUL in a name or symbol stringAddition/queryValueError
Integer outside signed 64-bit rangeAddition/queryOverflowError
Too many terms for the public facadeAddition/queryValueError
Enumeration arity is not an integer, or is boolEnumerationTypeError
Enumeration arity is negative or exceeds the facade ceilingEnumerationValueError

The facade ceiling is not a declaration of each predicate's arity. A three-term owns fact can pass the Python shape check even if the domain declares owns/2. Exact vocabulary validation happens in the engine. Shape errors normally mean a caller bug: fix the call rather than treating them as a negative policy decision.

Engine errors — MaelysDatalogError

Native storage errors can now occur at addition: the total entry limit, individual text byte bounds and allocation failures. Unknown predicates, wrong declared arity, forbidden predicate kinds, symbol-pool and per-predicate limits remain solve-time checks. The buffer is independent of a selected policy. Keep the exception handler around both addition and solve.

MaelysDatalogError is a subclass of RuntimeError. Its .status and .code carry the facade's operation status; .message and .hint explain it. The full .diagnostic is separate. Do not import the old binding's C error namespace or assume its specialized registration exception classes exist here. See Diagnostics for the distinction between status and diagnostic code.

Catching both

The exceptions come from different layers: MaelysDatalogError is a RuntimeError, while TypeError, ValueError and OverflowError are not. An except MaelysDatalogError clause therefore does not catch a malformed Python call. Keep both addition and solve inside the protected block:

CODE
try:
    edb.add_fact(predicate, terms)   # Python shape + native storage validation.
    result = ruleset.solve(edb)     # Native vocabulary/capacity validation.
except (TypeError, ValueError, OverflowError):
    raise                          # Fix the caller's representation.
except MaelysDatalogError as exc:
    print(exc.status, exc.message, exc.hint)
    raise                          # Never turn an engine failure into ALLOW.

In practice the first clause is a development guard rail, while the second is where native runtime conditions land. A wrong owner thread or use after close is a separate lifecycle RuntimeError, not a policy decision.