Error
tuprolog.solve.exception.error
¶
ISO Prolog errors: the error(Type, Extra) terms predicates throw, one family per kind.
When a built-in predicate cannot do its job because of its arguments or of the system, ISO Prolog
has it throw a term error(Type, Extra): Type classifies the problem, and Extra carries
implementation-defined details (2P-Kt puts a human-readable message there). Prolog code handles
them with catch(Goal, error(Type, _), Recovery). In this library each error is a
tuprolog.solve.exception.LogicError, of the subclass matching its family:
| Family (sub-package) | Type |
Meaning |
|---|---|---|
instantiation |
instantiation_error |
an argument is unbound, but a value is needed |
type |
type_error(Type, Culprit) |
Culprit is not of type Type (e.g. integer) |
domain |
domain_error(Domain, Culprit) |
Culprit is of the right type, not in Domain |
existence |
existence_error(Kind, Culprit) |
there is no Kind object Culprit |
permission |
permission_error(Op, Kind, Culprit) |
Op is not allowed on Culprit |
representation |
representation_error(Limit) |
an implementation limit is exceeded |
evaluation |
evaluation_error(Error) |
an arithmetic expression cannot be evaluated |
syntax |
syntax_error |
some text being read is not valid Prolog |
system |
system_error |
an internal problem, e.g. an exception raised by Python code |
message |
any thrown term | a term fitting no ISO family (e.g. throw(my_problem)) |
This package re-exports every family: error classes, the enumerations of their parameters (e.g.
Type, Domain) with their values as constants (e.g. TYPE_INTEGER, DOMAIN_IO_MODE), and the
factories building errors (e.g. type_error_for_argument), which take the execution context the
error occurs in (in a primitive, the request's context). TypeError, PermissionError,
SyntaxError, and SystemError must be imported explicitly, as they shadow Python's built-ins.
Primitives raise these errors (or reply with them) to signal problems; the argument checks of
tuprolog.solve.primitive (ensuring_*) raise the standard ones.
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.library import library
>>> from tuprolog.solve.primitive import primitive
>>> from tuprolog.solve.prolog import prolog_solver
>>> def colour(request):
... [argument] = request.arguments
... if str(argument) not in ("red", "green"):
... domain = expected_domain("flag_value")
... raise domain_error_for_argument(
... request.context, request.signature, domain, argument, 0
... )
... yield request.reply_success()
>>> lib = library("demo", primitives={"colour/1": primitive(colour)})
>>> solver = prolog_solver(libraries=lib)
>>> solver.solve_once("catch(colour(blue), error(E, _), true)")["E"]
domain_error(flag_value, blue)
See Also
tuprolog.solve.exception, for the other exceptions;
tuprolog.errors, for the Python exception classes of each family;
2P-Kt's documentation on
errors and exceptions.
DomainError
module-attribute
¶
DomainError = errors.DomainError
The domain error, thrown as error(domain_error(Domain, Culprit), _).
It means that Culprit is not in Domain.
The JVM class (also a Python ValueError and a tuprolog.errors.PrologDomainError). Members
(snake_case aliases as well): expected_domain, the Domain; culprit, the offending term;
besides those of tuprolog.solve.exception.LogicError (e.g. type, error_struct, message).
Domain
module-attribute
¶
Domain = DomainError.Expected
The enumeration of the domains a domain error may refer to (2P-Kt's DomainError.Expected).
Each value (also available as a DOMAIN_* constant) is the Domain of a
domain_error(Domain, Culprit) term: to_term() gives it as an atom (e.g. io_mode), and
domain as a string. Domain.of(name) and Domain.fromTerm(term) look a value up (see
expected_domain).
Examples:
>>> Domain.IO_MODE.to_term()
io_mode
DOMAIN_ATOM_PROPERTY
module-attribute
¶
DOMAIN_ATOM_PROPERTY = Domain.ATOM_PROPERTY
atom_property: the expected domain is a property of atoms.
DOMAIN_BUFFERING_MODE
module-attribute
¶
DOMAIN_BUFFERING_MODE = Domain.BUFFERING_MODE
buffering_mode: the expected domain is a buffering mode of streams (e.g. line, block).
DOMAIN_CHARACTER_CODE_LIST
module-attribute
¶
DOMAIN_CHARACTER_CODE_LIST = Domain.CHARACTER_CODE_LIST
character_code_list: the expected domain is a list of character codes.
DOMAIN_CLOSE_OPTION
module-attribute
¶
DOMAIN_CLOSE_OPTION = Domain.CLOSE_OPTION
close_option: the expected domain is an option of close/2 (e.g. force(true)).
DOMAIN_DATE_TIME
module-attribute
¶
DOMAIN_DATE_TIME = Domain.DATE_TIME
date_time: the expected domain is a date-time.
DOMAIN_EOF_ACTION
module-attribute
¶
DOMAIN_EOF_ACTION = Domain.EOF_ACTION
eof_action: the expected domain is an end-of-stream action (error, eof_code, reset).
DOMAIN_FLAG_VALUE
module-attribute
¶
DOMAIN_FLAG_VALUE = Domain.FLAG_VALUE
flag_value: the expected domain is an admissible value of a Prolog flag.
DOMAIN_FORMAT_CONTROL_SEQUENCE
module-attribute
¶
DOMAIN_FORMAT_CONTROL_SEQUENCE = (
Domain.FORMAT_CONTROL_SEQUENCE
)
format_control_sequence: the expected domain is a control sequence of format/2,3.
DOMAIN_IO_MODE
module-attribute
¶
DOMAIN_IO_MODE = Domain.IO_MODE
io_mode: the expected domain is a mode of opening streams (read, write, append).
DOMAIN_WELL_FORMED_LIST
module-attribute
¶
DOMAIN_WELL_FORMED_LIST = Domain.WELL_FORMED_LIST
well_formed_list: the expected domain is a well-formed list, i.e. one ending with [].
DOMAIN_NON_EMPTY_LIST
module-attribute
¶
DOMAIN_NON_EMPTY_LIST = Domain.NON_EMPTY_LIST
non_empty_list: the expected domain is a non-empty list.
DOMAIN_NOT_LESS_THAN_ZERO
module-attribute
¶
DOMAIN_NOT_LESS_THAN_ZERO = Domain.NOT_LESS_THAN_ZERO
not_less_than_zero: the expected domain is a non-negative number.
DOMAIN_OPERATOR_PRIORITY
module-attribute
¶
DOMAIN_OPERATOR_PRIORITY = Domain.OPERATOR_PRIORITY
operator_priority: the expected domain is an operator priority (an integer, 0 to 1200).
DOMAIN_OPERATOR_SPECIFIER
module-attribute
¶
DOMAIN_OPERATOR_SPECIFIER = Domain.OPERATOR_SPECIFIER
operator_specifier: the expected domain is an operator specifier (e.g. xfx, fy, yfx).
DOMAIN_ORDER
module-attribute
¶
DOMAIN_ORDER = Domain.ORDER
order: the expected domain is a comparison order (<, =, >).
DOMAIN_OS_FILE_PERMISSION
module-attribute
¶
DOMAIN_OS_FILE_PERMISSION = Domain.OS_FILE_PERMISSION
os_file_permission: the expected domain is a permission of files in the operating system.
DOMAIN_OS_FILE_PROPERTY
module-attribute
¶
DOMAIN_OS_FILE_PROPERTY = Domain.OS_FILE_PROPERTY
os_file_property: the expected domain is a property of files in the operating system.
DOMAIN_OS_PATH
module-attribute
¶
DOMAIN_OS_PATH = Domain.OS_PATH
os_path: the expected domain is a path of the operating system.
DOMAIN_PREDICATE_PROPERTY
module-attribute
¶
DOMAIN_PREDICATE_PROPERTY = Domain.PREDICATE_PROPERTY
predicate_property: the expected domain is a property of predicates (e.g. dynamic).
DOMAIN_FLAG
module-attribute
¶
DOMAIN_FLAG = Domain.FLAG
flag: the expected domain is the name of a Prolog flag.
DOMAIN_READ_OPTION
module-attribute
¶
DOMAIN_READ_OPTION = Domain.READ_OPTION
read_option: the expected domain is an option of read_term/2,3 (e.g. variables(Vs)).
DOMAIN_SELECTABLE_ITEM
module-attribute
¶
DOMAIN_SELECTABLE_ITEM = Domain.SELECTABLE_ITEM
selectable_item: the expected domain is an item that can be selected.
DOMAIN_SOCKET_ADDRESS
module-attribute
¶
DOMAIN_SOCKET_ADDRESS = Domain.SOCKET_ADDRESS
socket_address: the expected domain is a socket address.
DOMAIN_SOCKET_DOMAIN
module-attribute
¶
DOMAIN_SOCKET_DOMAIN = Domain.SOCKET_DOMAIN
socket_domain: the expected domain is a socket domain.
DOMAIN_SOURCE_SINK
module-attribute
¶
DOMAIN_SOURCE_SINK = Domain.SOURCE_SINK
source_sink: the expected domain is a source or sink of a stream (e.g. a file name or URL).
DOMAIN_STREAM
module-attribute
¶
DOMAIN_STREAM = Domain.STREAM
stream: the expected domain is a stream.
DOMAIN_STREAM_OPTION
module-attribute
¶
DOMAIN_STREAM_OPTION = Domain.STREAM_OPTION
stream_option: the expected domain is an option of open/4 (e.g. alias(A)).
DOMAIN_STREAM_OR_ALIAS
module-attribute
¶
DOMAIN_STREAM_OR_ALIAS = Domain.STREAM_OR_ALIAS
stream_or_alias: the expected domain is a stream, or the alias of one.
DOMAIN_STREAM_POSITION
module-attribute
¶
DOMAIN_STREAM_POSITION = Domain.STREAM_POSITION
stream_position: the expected domain is a position in a stream.
DOMAIN_STREAM_PROPERTY
module-attribute
¶
DOMAIN_STREAM_PROPERTY = Domain.STREAM_PROPERTY
stream_property: the expected domain is a property of streams (e.g. alias(A), input).
DOMAIN_STREAM_SEEK_METHOD
module-attribute
¶
DOMAIN_STREAM_SEEK_METHOD = Domain.STREAM_SEEK_METHOD
stream_seek_method: the expected domain is a method of seeking in a stream.
DOMAIN_STREAM_TYPE
module-attribute
¶
DOMAIN_STREAM_TYPE = Domain.STREAM_TYPE
stream_type: the expected domain is a type of streams (text, binary).
DOMAIN_TERM_STREAM_OR_ALIAS
module-attribute
¶
DOMAIN_TERM_STREAM_OR_ALIAS = Domain.TERM_STREAM_OR_ALIAS
term_stream_or_alias: the expected domain is a term stream, or the alias of one.
DOMAIN_VAR_BINDING_OPTION
module-attribute
¶
DOMAIN_VAR_BINDING_OPTION = Domain.VAR_BINDING_OPTION
var_binding_option: the expected domain is an option binding variables.
DOMAIN_WRITE_OPTION
module-attribute
¶
DOMAIN_WRITE_OPTION = Domain.WRITE_OPTION
write_option: the expected domain is an option of write_term/2,3 (e.g. quoted(true)).
DOMAIN_CLAUSE
module-attribute
¶
DOMAIN_CLAUSE = Domain.CLAUSE
clause: the expected domain is a well-formed clause.
That is, a callable term, or a Head :- Body one with a callable head and body.
DOMAIN_RULE
module-attribute
¶
DOMAIN_RULE = Domain.RULE
rule: the expected domain is a rule, i.e. a Head :- Body clause.
DOMAIN_FACT
module-attribute
¶
DOMAIN_FACT = Domain.FACT
fact: the expected domain is a fact, i.e. a clause with no body.
DOMAIN_DIRECTIVE
module-attribute
¶
DOMAIN_DIRECTIVE = Domain.DIRECTIVE
directive: the expected domain is a directive, i.e. a :- Goal clause.
EvaluationError
module-attribute
¶
EvaluationError = errors.EvaluationError
The evaluation error, thrown as error(evaluation_error(Error), _): an expression failed.
The JVM class (also a Python ArithmeticError and a tuprolog.errors.PrologEvaluationError).
Members (snake_case aliases as well): error_type, the ErrorType; besides those of
tuprolog.solve.exception.LogicError (e.g. type, error_struct, message).
ErrorType
module-attribute
¶
ErrorType = EvaluationError.Type
The enumeration of the kinds of evaluation errors (2P-Kt's EvaluationError.Type).
Each value (also available as an ERROR_* constant) is the Error of an
evaluation_error(Error) term: to_term() gives it as an atom (e.g. zero_divisor).
ErrorType.valueOf(NAME) and ErrorType.fromTerm(term) look a value up (see error_type).
ERROR_INT_OVERFLOW
module-attribute
¶
ERROR_INT_OVERFLOW = ErrorType.INT_OVERFLOW
int_overflow: an integer result is too large to be represented.
ERROR_FLOAT_OVERFLOW
module-attribute
¶
ERROR_FLOAT_OVERFLOW = ErrorType.FLOAT_OVERFLOW
float_overflow: a floating-point result is too large to be represented.
ERROR_UNDERFLOW
module-attribute
¶
ERROR_UNDERFLOW = ErrorType.UNDERFLOW
underflow: a floating-point result is too small to be represented.
ERROR_ZERO_DIVISOR
module-attribute
¶
ERROR_ZERO_DIVISOR = ErrorType.ZERO_DIVISOR
zero_divisor: a number is divided by zero.
ERROR_UNDEFINED
module-attribute
¶
ERROR_UNDEFINED = ErrorType.UNDEFINED
undefined: the result is mathematically undefined (e.g. 0 / 0, log(0)).
ExistenceError
module-attribute
¶
ExistenceError = errors.ExistenceError
The existence error, thrown as error(existence_error(Kind, Culprit), _).
It means that there is no object Culprit of kind Kind.
The JVM class (also a Python LookupError and a tuprolog.errors.PrologExistenceError).
Members (snake_case aliases as well): expected_object, the ObjectType; culprit, the term
naming the missing object; besides those of tuprolog.solve.exception.LogicError (e.g. type,
error_struct, message).
ObjectType
module-attribute
¶
ObjectType = ExistenceError.ObjectType
The enumeration of the kinds of objects of existence errors (2P-Kt's ObjectType).
Each value (also available as an OBJECT_* constant) is the Kind of an
existence_error(Kind, Culprit) term: to_term() gives it as an atom (e.g. procedure).
ObjectType.of(NAME) (upper-case names only) and ObjectType.fromTerm(term) look a value up
(see object_type, accepting any case).
OBJECT_PROCEDURE
module-attribute
¶
OBJECT_PROCEDURE = ObjectType.PROCEDURE
procedure: a predicate (the culprit is its indicator, e.g. foo/1).
OBJECT_SOURCE_SINK
module-attribute
¶
OBJECT_SOURCE_SINK = ObjectType.SOURCE_SINK
source_sink: a source or sink of streams, e.g. a file, or a stream alias.
OBJECT_RESOURCE
module-attribute
¶
OBJECT_RESOURCE = ObjectType.RESOURCE
resource: a resource, e.g. one to load.
OBJECT_OOP_ALIAS
module-attribute
¶
OBJECT_OOP_ALIAS = ObjectType.OOP_ALIAS
oop_alias: an OOPLib alias ($Alias) or type name (see tuprolog.solve.libs).
OBJECT_OOP_METHOD
module-attribute
¶
OBJECT_OOP_METHOD = ObjectType.OOP_METHOD
oop_method: a method or attribute of an object, called through OOPLib.
OBJECT_OOP_CONSTRUCTOR
module-attribute
¶
OBJECT_OOP_CONSTRUCTOR = ObjectType.OOP_CONSTRUCTOR
oop_constructor: a constructor of a type, called through OOPLib.
OBJECT_OOP_PROPERTY
module-attribute
¶
OBJECT_OOP_PROPERTY = ObjectType.OOP_PROPERTY
oop_property: a property of an object, accessed through OOPLib.
InstantiationError
module-attribute
¶
InstantiationError = _errors.InstantiationError
The instantiation error, thrown as error(instantiation_error, _): a term is unbound.
The JVM class (also a Python ValueError and a tuprolog.errors.PrologInstantiationError).
Members (snake_case aliases as well): culprit, the unbound variable; besides those of
tuprolog.solve.exception.LogicError (e.g. type, error_struct, message).
MessageError
module-attribute
¶
MessageError = _errors.MessageError
The error carrying an arbitrary thrown term, used when no other LogicError fits.
The JVM class (also a tuprolog.errors.PrologMessageError). Members (snake_case aliases as
well): content, the thrown term; besides those of tuprolog.solve.exception.LogicError.
Operation
module-attribute
¶
Operation = PermissionError.Operation
The enumeration of the operations of permission errors (2P-Kt's PermissionError.Operation).
Each value (also available as an OPERATION_* constant) is the Operation of a
permission_error(Operation, Kind, Culprit) term: to_term() gives it as an atom (e.g.
modify), and operation as a string. Operation.of(name) and Operation.fromTerm(term) look
a value up (see operation).
Permission
module-attribute
¶
Permission = PermissionError.Permission
The enumeration of the kinds of objects of permission errors (2P-Kt's Permission).
Each value (also available as a PERMISSION_* constant) is the Kind of a
permission_error(Operation, Kind, Culprit) term: to_term() gives it as an atom (e.g.
static_procedure), and permission as a string. Permission.of(name) and
Permission.fromTerm(term) look a value up (see permission_type).
OPERATION_ACCESS
module-attribute
¶
OPERATION_ACCESS = Operation.ACCESS
access: the operation of accessing an object.
E.g. reading a private procedure's clauses, or a private attribute through OOPLib.
OPERATION_ADD_ALIAS
module-attribute
¶
OPERATION_ADD_ALIAS = Operation.ADD_ALIAS
add_alias: the operation of adding an alias (e.g. to a stream, or an OOPLib alias in use).
OPERATION_CLOSE
module-attribute
¶
OPERATION_CLOSE = Operation.CLOSE
close: the operation of closing a stream.
OPERATION_CREATE
module-attribute
¶
OPERATION_CREATE = Operation.CREATE
create: the operation of creating an object (e.g. an operator, or a flag).
OPERATION_INPUT
module-attribute
¶
OPERATION_INPUT = Operation.INPUT
input: the operation of reading from a stream.
OPERATION_INVOKE
module-attribute
¶
OPERATION_INVOKE = Operation.INVOKE
invoke: the operation of invoking a method through OOPLib.
OPERATION_MODIFY
module-attribute
¶
OPERATION_MODIFY = Operation.MODIFY
modify: the operation of modifying an object (e.g. asserting or retracting clauses).
OPERATION_OPEN
module-attribute
¶
OPERATION_OPEN = Operation.OPEN
open: the operation of opening a source or sink.
OPERATION_OUTPUT
module-attribute
¶
OPERATION_OUTPUT = Operation.OUTPUT
output: the operation of writing on a stream.
OPERATION_REPOSITION
module-attribute
¶
OPERATION_REPOSITION = Operation.REPOSITION
reposition: the operation of repositioning a stream.
PERMISSION_BINARY_STREAM
module-attribute
¶
PERMISSION_BINARY_STREAM = Permission.BINARY_STREAM
binary_stream: the object is a binary stream.
PERMISSION_FLAG
module-attribute
¶
PERMISSION_FLAG = Permission.FLAG
flag: the object is a Prolog flag (e.g. a read-only one).
Also used by OOPLib for aliases already registered.
PERMISSION_OPERATOR
module-attribute
¶
PERMISSION_OPERATOR = Permission.OPERATOR
operator: the object is an operator (e.g. ,, which cannot be redefined).
PERMISSION_PAST_END_OF_STREAM
module-attribute
¶
PERMISSION_PAST_END_OF_STREAM = (
Permission.PAST_END_OF_STREAM
)
past_end_of_stream: the object is a stream already past its end.
PERMISSION_PRIVATE_PROCEDURE
module-attribute
¶
PERMISSION_PRIVATE_PROCEDURE = Permission.PRIVATE_PROCEDURE
private_procedure: the object is a private procedure, i.e. a predicate defined by a library.
PERMISSION_SOURCE_SINK
module-attribute
¶
PERMISSION_SOURCE_SINK = Permission.SOURCE_SINK
source_sink: the object is a source or sink of streams.
PERMISSION_STATIC_PROCEDURE
module-attribute
¶
PERMISSION_STATIC_PROCEDURE = Permission.STATIC_PROCEDURE
static_procedure: the object is a static procedure (of the static knowledge base).
PERMISSION_OOP_METHOD
module-attribute
¶
PERMISSION_OOP_METHOD = Permission.OOP_METHOD
oop_method: the object is a method or attribute of an object, accessed through OOPLib.
PERMISSION_STREAM
module-attribute
¶
PERMISSION_STREAM = Permission.STREAM
stream: the object is a stream.
PERMISSION_TEXT_STREAM
module-attribute
¶
PERMISSION_TEXT_STREAM = Permission.TEXT_STREAM
text_stream: the object is a text stream.
RepresentationError
module-attribute
¶
RepresentationError = _errors.RepresentationError
The representation error: a limit is exceeded, thrown as error(representation_error(Limit), _).
The JVM class (also a Python ValueError and a tuprolog.errors.PrologRepresentationError).
Members (snake_case aliases as well): limit, the exceeded Limit; besides those of
tuprolog.solve.exception.LogicError (e.g. type, error_struct, message).
Limit
module-attribute
¶
Limit = RepresentationError.Limit
The enumeration of the limits of representation errors (2P-Kt's RepresentationError.Limit).
Each value (also available as a LIMIT_* constant) is the Limit of a
representation_error(Limit) term: to_term() gives it as an atom (e.g. max_arity), and
limit as a string. Limit.of(name) and Limit.fromTerm(term) look a value up (see limit).
LIMIT_CHARACTER
module-attribute
¶
LIMIT_CHARACTER = Limit.CHARACTER
character: the exceeded limit is the set of characters.
LIMIT_CHARACTER_CODE
module-attribute
¶
LIMIT_CHARACTER_CODE = Limit.CHARACTER_CODE
character_code: the exceeded limit is the range of character codes (0 to 65535).
LIMIT_IN_CHARACTER_CODE
module-attribute
¶
LIMIT_IN_CHARACTER_CODE = Limit.IN_CHARACTER_CODE
in_character_code: the exceeded limit is the range of input character codes.
That is, character codes, or -1 for the end of file.
LIMIT_MAX_ARITY
module-attribute
¶
LIMIT_MAX_ARITY = Limit.MAX_ARITY
max_arity: the exceeded limit is the maximum arity of compound terms (the max_arity flag).
LIMIT_MAX_INTEGER
module-attribute
¶
LIMIT_MAX_INTEGER = Limit.MAX_INTEGER
max_integer: the exceeded limit is the greatest integer (the max_integer flag).
LIMIT_MIN_INTEGER
module-attribute
¶
LIMIT_MIN_INTEGER = Limit.MIN_INTEGER
min_integer: the exceeded limit is the least integer (the min_integer flag).
LIMIT_OOP_OBJECT
module-attribute
¶
LIMIT_OOP_OBJECT = Limit.OOP_OBJECT
oop_object: the exceeded limit is the objects a term can be converted into, through OOPLib.
See tuprolog.solve.libs.
LIMIT_TOO_MANY_VARIABLES
module-attribute
¶
LIMIT_TOO_MANY_VARIABLES = Limit.TOO_MANY_VARIABLES
too_many_variables: the exceeded limit is the number of variables a term may contain.
Type
module-attribute
¶
Type = TypeError.Expected
The enumeration of the types a type error may expect (2P-Kt's TypeError.Expected).
Each value (also available as a TYPE_* constant) is the Type of a
type_error(Type, Culprit) term: to_term() gives it as an atom (e.g. integer).
Type.of(name) and Type.fromTerm(term) look a value up (see expected_type).
Examples:
>>> Type.INTEGER.to_term()
integer
TYPE_ATOMIC
module-attribute
¶
TYPE_ATOMIC = Type.ATOMIC
atomic: the expected type is an atomic term, i.e. an atom or a number.
TYPE_BOOLEAN
module-attribute
¶
TYPE_BOOLEAN = Type.BOOLEAN
boolean: the expected type is a boolean, i.e. true or false.
TYPE_BYTE
module-attribute
¶
TYPE_BYTE = Type.BYTE
byte: the expected type is a byte, i.e. an integer from 0 to 255.
TYPE_CALLABLE
module-attribute
¶
TYPE_CALLABLE = Type.CALLABLE
callable: the expected type is a callable term, i.e. an atom or a compound term (a goal).
TYPE_CHARACTER
module-attribute
¶
TYPE_CHARACTER = Type.CHARACTER
character: the expected type is a character, i.e. an atom of length 1.
TYPE_COMPOUND
module-attribute
¶
TYPE_COMPOUND = Type.COMPOUND
compound: the expected type is a compound term, i.e. a structure with arguments.
TYPE_DEALIASING_EXPRESSION
module-attribute
¶
TYPE_DEALIASING_EXPRESSION = Type.DEALIASING_EXPRESSION
dealiasing_expression: the expected type is a de-aliasing expression of OOPLib.
That is, $Alias with an atom Alias (see tuprolog.solve.libs).
TYPE_EVALUABLE
module-attribute
¶
TYPE_EVALUABLE = Type.EVALUABLE
evaluable: the expected type is an evaluable functor, i.e. one of an arithmetic function.
The culprit is the indicator of the functor, e.g. foo/1.
TYPE_FLOAT
module-attribute
¶
TYPE_FLOAT = Type.FLOAT
float: the expected type is a floating-point number.
TYPE_INTEGER
module-attribute
¶
TYPE_INTEGER = Type.INTEGER
integer: the expected type is an integer.
TYPE_IN_CHARACTER
module-attribute
¶
TYPE_IN_CHARACTER = Type.IN_CHARACTER
in_character: the expected type is an input character, i.e. a character or end_of_file.
TYPE_NUMBER
module-attribute
¶
TYPE_NUMBER = Type.NUMBER
number: the expected type is a number, i.e. an integer or a floating-point one.
TYPE_OBJECT_REFERENCE
module-attribute
¶
TYPE_OBJECT_REFERENCE = Type.OBJECT_REFERENCE
object_reference: the expected type is a reference to a Python object.
See OOPLib, in tuprolog.solve.libs.
TYPE_PAIR
module-attribute
¶
TYPE_PAIR = Type.PAIR
pair: the expected type is a pair, i.e. a Key - Value term.
TYPE_PREDICATE_INDICATOR
module-attribute
¶
TYPE_PREDICATE_INDICATOR = Type.PREDICATE_INDICATOR
predicate_indicator: the expected type is a predicate indicator, i.e. a Name/Arity term.
TYPE_REFERENCE
module-attribute
¶
TYPE_REFERENCE = Type.REFERENCE
reference: the expected type is a reference to a Python object or type.
See OOPLib, in tuprolog.solve.libs.
TYPE_TYPE_REFERENCE
module-attribute
¶
TYPE_TYPE_REFERENCE = Type.TYPE_REFERENCE
type_reference: the expected type is a reference to a Python type.
See OOPLib, in tuprolog.solve.libs.
TYPE_URL
module-attribute
¶
TYPE_URL = Type.URL
url: the expected type is a URL or a file path, e.g. for open/3,4 or consult/1.
TYPE_VARIABLE
module-attribute
¶
TYPE_VARIABLE = Type.VARIABLE
variable: the expected type is an unbound variable.
domain_error_for_flag_values
¶
domain_error_for_flag_values(
context: ExecutionContext,
procedure: Signature,
flag_values: Iterable[Term],
actual: Term,
index: int | None = None,
) -> DomainError
Creates the domain error for an argument that should be one of some values, e.g. of a flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
flag_values
|
Iterable[Term]
|
the admissible values. |
required |
actual
|
Term
|
the offending argument. |
required |
index
|
int | None
|
the (0-based) position of the offending argument, if known (it only changes the message). |
None
|
Returns:
| Type | Description |
|---|---|
DomainError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import atom
>>> error = domain_error_for_flag_values(
... context, signature("foo", 1), [atom("on"), atom("off")], atom("maybe"), 0
... )
>>> error.type
domain_error(flag_value, maybe)
domain_error_for_argument
¶
domain_error_for_argument(
context: ExecutionContext,
procedure: Signature,
expected: Domain,
actual: Term,
index: int | None = None,
) -> DomainError
Creates the domain error for an argument of a predicate outside the expected domain.
The usual way of reporting that a primitive received an argument of the right type but with an inadmissible value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
expected
|
Domain
|
the expected domain (e.g. |
required |
actual
|
Term
|
the offending argument. |
required |
index
|
int | None
|
the (0-based) position of the offending argument, if known (it only changes the message). |
None
|
Returns:
| Type | Description |
|---|---|
DomainError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import integer
>>> procedure = signature("foo", 2)
>>> domain = DOMAIN_NOT_LESS_THAN_ZERO
>>> error = domain_error_for_argument(context, procedure, domain, integer(-1), 1)
>>> error.type
domain_error(not_less_than_zero, -1)
domain_error_for_term
¶
domain_error_for_term(
context: ExecutionContext,
expected: Domain,
actual_value: Term,
) -> DomainError
Creates the domain error for a term outside the expected domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
expected
|
Domain
|
the expected domain. |
required |
actual_value
|
Term
|
the offending term. |
required |
Returns:
| Type | Description |
|---|---|
DomainError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import atom
>>> domain_error_for_term(context, DOMAIN_IO_MODE, atom("rw")).message
'Term `rw` is not a valid io_mode'
domain_error_for_goal
¶
domain_error_for_goal(
context: ExecutionContext,
procedure: Signature,
expected: Domain,
actual: Term,
) -> DomainError
Creates the domain error for a sub-goal of a predicate outside the expected domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
expected
|
Domain
|
the expected domain (e.g. |
required |
actual
|
Term
|
the offending sub-goal. |
required |
Returns:
| Type | Description |
|---|---|
DomainError
|
The error, thrown as |
expected_domain
¶
The Domain named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
Domain
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.exception.error.domain import *
>>> expected_domain("io_mode") == expected_domain(atom("io_mode")) == DOMAIN_IO_MODE
True
evaluation_error
¶
evaluation_error(
context: ExecutionContext, type: ErrorType, message: str
) -> EvaluationError
Creates an evaluation error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
type
|
ErrorType
|
the kind of error (e.g. |
required |
message
|
str
|
the error message, also the error term's extra data. |
required |
Returns:
| Type | Description |
|---|---|
EvaluationError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> evaluation_error(context, ERROR_ZERO_DIVISOR, "division by zero").error_struct
error(evaluation_error(zero_divisor), 'division by zero')
error_type
¶
The ErrorType named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
ErrorType
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.exception.error.evaluation import *
>>> error_type("zero_divisor") == error_type(atom("zero_divisor")) == ERROR_ZERO_DIVISOR
True
existence_error
¶
existence_error(
context: ExecutionContext,
type: ObjectType,
culprit: Term,
message: str,
) -> ExistenceError
Creates an existence error for any kind of object, with a custom message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
type
|
ObjectType
|
the kind of the missing object (e.g. |
required |
culprit
|
Term
|
the term naming the missing object. |
required |
message
|
str
|
the error message. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import atom
>>> existence_error(context, OBJECT_OOP_METHOD, atom("foo"), "no method foo").type
existence_error(oop_method, foo)
existence_error_for_source_sink
¶
existence_error_for_source_sink(
context: ExecutionContext, alias: Atom | str
) -> ExistenceError
Creates the existence error for a stream alias no stream has.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
alias
|
Atom | str
|
the alias, as an atom or a string. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
existence_error_for_procedure
¶
existence_error_for_procedure(
context: ExecutionContext, procedure: Signature
) -> ExistenceError
Creates the existence error for an undefined predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the undefined predicate. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> existence_error_for_procedure(context, signature("foo", 1)).type
existence_error(procedure, foo/1)
existence_error_for_stream
¶
existence_error_for_stream(
context: ExecutionContext, stream: Term
) -> ExistenceError
Creates the existence error for a stream that does not exist (e.g. a closed one).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
stream
|
Term
|
the term denoting the stream. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
existence_error_for_resource
¶
existence_error_for_resource(
context: ExecutionContext, name: str
) -> ExistenceError
Creates the existence error for a missing resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
name
|
str
|
the name of the resource. |
required |
Returns:
| Type | Description |
|---|---|
ExistenceError
|
The error, thrown as |
object_type
¶
object_type(name: str | Term) -> ObjectType
The ObjectType named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string or an atom (case-insensitive, e.g. |
required |
Returns:
| Type | Description |
|---|---|
ObjectType
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Note
Unlike the other error enumerations, 2P-Kt's ObjectType.of and fromTerm only accept
upper-case names: this function upper-cases strings and atoms first.
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.exception.error.existence import *
>>> object_type("procedure") == object_type(atom("procedure")) == OBJECT_PROCEDURE
True
instantiation_error_for_argument
¶
instantiation_error_for_argument(
context: ExecutionContext,
procedure: Signature,
variable: Var,
index: int | None = None,
) -> InstantiationError
Creates the instantiation error for an unbound argument of a predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
variable
|
Var
|
the unbound variable. |
required |
index
|
int | None
|
the (0-based) position of the offending argument, if known (it only changes the message). |
None
|
Returns:
| Type | Description |
|---|---|
InstantiationError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import var
>>> error = instantiation_error_for_argument(context, signature("foo", 2), var("X"), 0)
>>> error.type
instantiation_error
>>> error.message
'The 0-th argument `X` of foo/2 is unexpectedly not instantiated'
instantiation_error_for_goal
¶
instantiation_error_for_goal(
context: ExecutionContext,
procedure: Signature,
variable: Var,
) -> InstantiationError
Creates the instantiation error for an unbound sub-goal of a predicate (e.g. call(X)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
variable
|
Var
|
the unbound sub-goal. |
required |
Returns:
| Type | Description |
|---|---|
InstantiationError
|
The error, thrown as |
message_error
¶
message_error(
content: Term,
context: ExecutionContext,
cause: Any = None,
) -> MessageError
Creates the error throwing an arbitrary term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
Term
|
the term to throw; Prolog's |
required |
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
cause
|
Any
|
the exception causing this one, if any. |
None
|
Returns:
| Type | Description |
|---|---|
MessageError
|
The error. |
Note
Calls 2P-Kt's MessageError.Companion.of, which (not being static on the JVM) is not
reachable as MessageError.of.
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import atom
>>> message_error(atom("hello"), context).content
hello
permission_error
¶
permission_error(
context: ExecutionContext,
procedure: Signature,
operation: Operation,
permission: Permission,
culprit: Term,
) -> PermissionError
Creates a permission error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
operation
|
Operation
|
the attempted operation (e.g. |
required |
permission
|
Permission
|
the kind of the object (e.g. |
required |
culprit
|
Term
|
the object. |
required |
Returns:
| Type | Description |
|---|---|
PermissionError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import indicator
>>> error = permission_error(
... context,
... signature("assertz", 1),
... OPERATION_MODIFY,
... PERMISSION_STATIC_PROCEDURE,
... indicator("foo", 2),
... )
>>> error.type
permission_error(modify, static_procedure, foo/2)
operation
¶
The Operation named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
Operation
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.exception.error.permission import *
>>> operation("modify") == operation(atom("modify")) == OPERATION_MODIFY
True
permission_type
¶
permission_type(name: str | Term) -> Permission
The Permission named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
Permission
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.solve.exception.error.permission import *
>>> permission_type("static_procedure") == PERMISSION_STATIC_PROCEDURE
True
representation_error
¶
representation_error(
context: ExecutionContext,
procedure: Signature,
limit: Limit,
cause: Any = None,
) -> RepresentationError
Creates a representation error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
limit
|
Limit
|
the exceeded limit (e.g. |
required |
cause
|
Any
|
the exception causing this one, if any. |
None
|
Returns:
| Type | Description |
|---|---|
RepresentationError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> representation_error(context, signature("functor", 3), LIMIT_MAX_ARITY).type
representation_error(max_arity)
limit
¶
The Limit named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
Limit
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.solve.exception.error.representation import *
>>> limit("max_arity") == LIMIT_MAX_ARITY
True
syntax_error
¶
syntax_error(
context: ExecutionContext, message: str
) -> SyntaxError
Creates a syntax error with a message, without positional information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
message
|
str
|
the error message. |
required |
Returns:
| Type | Description |
|---|---|
SyntaxError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> syntax_error(context, "missing dot").message
'Syntax error: missing dot'
syntax_error_while_parsing_term
¶
syntax_error_while_parsing_term(
context: ExecutionContext,
input: str,
row: int,
column: int,
message: str,
) -> SyntaxError
Creates the syntax error for some text failing to parse as a term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
input
|
str
|
the text being parsed. |
required |
row
|
int
|
the (1-based) line where parsing failed. |
required |
column
|
int
|
the (1-based) column where parsing failed. |
required |
message
|
str
|
the detail message. |
required |
Returns:
| Type | Description |
|---|---|
SyntaxError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> syntax_error_while_parsing_term(context, "f(", 1, 3, "unexpected end").message
'Syntax error at 1:3 while parsing `f(`: unexpected end'
syntax_error_while_parsing_clauses
¶
syntax_error_while_parsing_clauses(
context: ExecutionContext,
input: str,
index: int,
row: int,
column: int,
message: str,
) -> SyntaxError
Creates the syntax error for a clause of some text failing to parse.
The message shows the offending lines, with a caret (^) under the offending column (see
error_detector).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
input
|
str
|
the text being parsed, e.g. a theory. |
required |
index
|
int
|
the index of the clause failing to parse. |
required |
row
|
int
|
the (1-based) line where parsing failed. |
required |
column
|
int
|
the (1-based) column where parsing failed. |
required |
message
|
str
|
the detail message. |
required |
Returns:
| Type | Description |
|---|---|
SyntaxError
|
The error, thrown as |
error_detector
¶
Renders a line of a text with a caret (^) under a column, for error messages.
The previous line, if any, is shown as well, for context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the text. |
required |
line
|
int
|
the (1-based) line to show. |
required |
column
|
int
|
the (1-based) column to point at. |
required |
message
|
str | None
|
a message to append after the caret, if any. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The rendered lines, each prefixed by its number. |
Examples:
>>> from tuprolog.solve.exception.error.syntax import error_detector
>>> print(error_detector("foo(bar baz)", 1, 9, "unexpected"))
1: foo(bar baz)
^ unexpected
system_error
¶
system_error(
context: ExecutionContext, exception: Any
) -> SystemError
Creates the system error wrapping an uncaught error, exception, or thrown term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
exception
|
Any
|
a |
required |
Returns:
| Type | Description |
|---|---|
SystemError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import atom
>>> system_error(context, atom("oops")).message
'Uncaught exception `oops`'
type_error
¶
type_error(
context: ExecutionContext,
expected: Type,
actual: Term,
message: str,
) -> TypeError
Creates a type error with a custom message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
expected
|
Type
|
the expected type (e.g. |
required |
actual
|
Term
|
the offending term. |
required |
message
|
str
|
the error message. |
required |
Returns:
| Type | Description |
|---|---|
TypeError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import integer
>>> type_error(context, TYPE_ATOM, integer(1), "not an atom").error_struct
error(type_error(atom, 1), 'not an atom')
type_error_for_argument_list
¶
type_error_for_argument_list(
context: ExecutionContext,
procedure: Signature,
expected: Type,
actual: Term,
index: int | None = None,
) -> TypeError
Creates the type error for an argument that should be a list of items of some type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
expected
|
Type
|
the type the items should have. |
required |
actual
|
Term
|
the offending argument. |
required |
index
|
int | None
|
the (0-based) position of the offending argument, if known (it only changes the message). |
None
|
Returns:
| Type | Description |
|---|---|
TypeError
|
The error, thrown as |
type_error_for_argument
¶
type_error_for_argument(
context: ExecutionContext,
procedure: Signature,
expected: Type,
actual: Term,
index: int | None = None,
) -> TypeError
Creates the type error for an argument of a predicate not having the expected type.
The usual way of reporting that a primitive received an argument of a wrong type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
expected
|
Type
|
the expected type (e.g. |
required |
actual
|
Term
|
the offending argument. |
required |
index
|
int | None
|
the (0-based) position of the offending argument, if known (it only changes the message). |
None
|
Returns:
| Type | Description |
|---|---|
TypeError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import atom
>>> procedure = signature("foo", 2)
>>> error = type_error_for_argument(context, procedure, TYPE_INTEGER, atom("a"), 0)
>>> error.type
type_error(integer, a)
>>> error.message
'The 0-th argument of `foo/2` should be a `integer`, but `a` has been provided instead'
type_error_for_term
¶
type_error_for_term(
context: ExecutionContext,
expected: Type,
actual_value: Term,
) -> TypeError
Creates the type error for a term not having the expected type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
expected
|
Type
|
the expected type. |
required |
actual_value
|
Term
|
the offending term. |
required |
Returns:
| Type | Description |
|---|---|
TypeError
|
The error, thrown as |
Note
2P-Kt has no TypeError.forTerm (unlike DomainError.forTerm): this mirrors its message.
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import integer
>>> type_error_for_term(context, TYPE_CALLABLE, integer(1)).message
'Term `1` is not a valid callable term'
type_error_for_goal
¶
type_error_for_goal(
context: ExecutionContext,
procedure: Signature,
expected: Type,
actual: Term,
) -> TypeError
Creates the type error for a sub-goal of a predicate not having the expected type.
E.g. for call/1 invoked with a non-callable goal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
expected
|
Type
|
the expected type (usually |
required |
actual
|
Term
|
the offending sub-goal. |
required |
Returns:
| Type | Description |
|---|---|
TypeError
|
The error, thrown as |
expected_type
¶
The Type named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
Type
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.exception.error.type import *
>>> expected_type("integer") == expected_type(atom("integer")) == TYPE_INTEGER
True