Skip to content

Exception adaptation and result classification

A Python call ends in a return value or an exception, and neither is safe to put on the wire as Python made it. The CPython provider classifies both against the sealed interface: a result becomes a value of the declared return type, an exception becomes either an error the method declares or one of a closed set of fault kinds. This page covers declared errors, the fault kinds and what each means for the session, and how results are checked.

Two classifications

flowchart TB
  CALL["Block callable returns or raises"]
  subgraph CLS["CLASSIFICATION AGAINST THE SEALED INTERFACE"]
    direction TB
    R{{"Result matches the<br/>declared return type?"}}
    E{{"Exception is the generated wrapper<br/>for an error this method declares?"}}
  end
  V["Typed value"]
  DE["Declared error<br/>ordinal and typed payload"]
  GF["Guest fault<br/>closed kind"]
  CALL -->|"returns"| R
  CALL -->|"raises"| E
  R -->|"yes"| V
  R -->|"no"| GF
  E -->|"yes"| DE
  E -->|"no"| GF

Declared errors

The generated binding defines the one Python wrapper that represents a declared interface error. The provider accepts the wrapper's ordinal when that error is declared on the selected method, then classifies its payload against the declared type. The caller receives the error ordinal and a typed payload.

Guest faults

Every other exception becomes a guest fault of a closed kind. A fault carries its kind; exception text, tracebacks and tenant values stay in the provider process.

Kind Raised when Session continues Attempt repeatable
undeclared_error Block code raised something the interface does not declare Yes No
adapter_contract_violation The adapter broke its contract: wrong arity, wrong type, or an outcome for an attempt never dispatched No No
value_encoding_failure A value could not be encoded as its declared type Yes Yes
resource_exhausted The provider ran out of a resource it needed Yes No
runtime_fatal The interpreter itself failed, leaving nothing safe to reuse No No
interrupted A cooperative interruption took effect Yes Yes
deadline_exceeded The deadline passed while the attempt was running Yes No

"Attempt repeatable" states what the fault itself permits. A retry also requires the method's retry contract to allow it. Both columns are properties of the language-neutral provider protocol and hold for every provider. See Provider outcomes and faults.

Result classification

A normal result is classified against the method's declared return type:

  • an integer is checked against the declared width;
  • a bool is accepted as a boolean and refused where an integer is declared;
  • a record or variant is an instance of the generated type bound to the interface hash;
  • a reference uses the declared generated reference class.

A result that fails its check becomes a value_encoding_failure fault. The wire carries values of declared types only. See The type model.