If py_call/2 or one of the other predicates that access Python causes Python to raise an exception, this exception is translated into a Prolog exception of the shape below. The library defines a rule for print_message/2 to render these errors in a human readable way.
error(python_error(ErrorType, Value)
, _)
Here, ErrorType is the name of the error type, as an atom,
e.g.,
’TypeError'
. Value is the exception object
represented by a Python object reference. The library(janus)
defines the message formatting, which makes us end up with a message
like below.
?- py_call(nomodule:noattr). ERROR: Python 'ModuleNotFoundError': ERROR: No module named 'nomodule' ERROR: In: ERROR: [10] janus:py_call(nomodule:noattr)
The Python stack trace is handed embedded into the second
argument of the error(Formal, ImplementationDefined)
. If an
exception is printed, printing the Python backtrace, is controlled by
the Prolog flags py_backtrace
(default true
)
and
py_backtrace_depth
(default 4
).