warning
tuprolog.solve.exception.warning
¶
Warnings: non-fatal problems a solver reports while solving, without stopping.
Some problems do not deserve to end a query with an error: e.g., by default, calling an
undefined predicate just fails (as the unknown flag is warning), and a failing initialization
directive does not prevent loading the rest of a theory. Solvers report such problems as
warnings (tuprolog.solve.exception.Warnings) on their warnings output channel, which prints
their messages on sys.stderr by default (pass warning=... to the solver factories, e.g.
tuprolog.solve.prolog.prolog_solver, to handle them otherwise).
Types: MissingPredicate and InitializationIssue, built by missing_predicate and
initialization_issue.
Examples:
>>> from tuprolog.solve.channel import output_channel
>>> from tuprolog.solve.prolog import prolog_solver
>>> warnings = []
>>> solver = prolog_solver(warning=output_channel(warnings.append))
>>> solver.solve_once("undefined").is_no
True
>>> [warning.message for warning in warnings]
['No such a predicate: undefined/0']
See Also
tuprolog.solve.exception, for the other exceptions;
tuprolog.solve.flags, for the unknown flag;
2P-Kt's documentation on
errors and exceptions.
InitializationIssue
module-attribute
¶
InitializationIssue = _warnings.InitializationIssue
The warning that an initialization goal, e.g. a directive of a theory, did not succeed.
Reported instead of aborting the loading of a theory, so that one misbehaving directive (e.g.
:- initialization(Goal).) does not prevent loading the rest.
Members (snake_case aliases as well): goal, the goal that failed or raised an error; cause,
the error it raised (None if it simply failed); besides those of
tuprolog.solve.exception.ResolutionException.
Examples:
>>> from tuprolog.solve.channel import output_channel
>>> from tuprolog.solve.prolog import prolog_solver
>>> from tuprolog.theory.parsing import parse_theory
>>> warnings = []
>>> _ = prolog_solver(
... static_kb=parse_theory(":- initialization(fail)."),
... warning=output_channel(warnings.append),
... )
>>> [(type(w) is InitializationIssue, str(w.goal), w.cause) for w in warnings]
[(True, 'fail', None)]
MissingPredicate
module-attribute
¶
MissingPredicate = _warnings.MissingPredicate
The warning that a goal called an undefined predicate.
Reported when the unknown flag is warning (the default; with error, an existence_error
is raised instead, and with fail the goal fails silently). The goal then fails.
Members (snake_case aliases as well): signature, the tuprolog.solve.Signature of the missing
predicate; besides those of tuprolog.solve.exception.ResolutionException.
initialization_issue
¶
initialization_issue(
goal: Struct,
context: ExecutionContext,
cause: ResolutionException | None = None,
) -> InitializationIssue
Creates the warning that an initialization goal did not succeed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal
|
Struct
|
the initialization goal (e.g. a directive's). |
required |
context
|
ExecutionContext
|
the execution context in which the goal was solved. |
required |
cause
|
ResolutionException | None
|
the error the goal raised, or |
None
|
Returns:
| Type | Description |
|---|---|
InitializationIssue
|
The warning. |
missing_predicate
¶
missing_predicate(
signature: Signature,
context: ExecutionContext,
cause: Any = None,
) -> MissingPredicate
Creates the warning that a goal called an undefined predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signature
|
Signature
|
the signature of the missing predicate. |
required |
context
|
ExecutionContext
|
the execution context of the call. |
required |
cause
|
Any
|
the exception causing this warning, if any. |
None
|
Returns:
| Type | Description |
|---|---|
MissingPredicate
|
The warning, whose message names the missing predicate. |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.prolog import prolog_solver
>>> from tuprolog.solve.exception.warning import missing_predicate
>>> context = prolog_solver().current_context
>>> missing_predicate(signature("foo", 1), context).message
'No such a predicate: foo/1'