Common Lisp Package: MORE-CONDITIONS

This package provides generic conditions and condition-related utilities. Conditions * `chainable-condition' * `missing-required-argument' * `missing-required-initarg' * `incompatible-arguments' * `incompatible-initargs' * `reference-condition' Condition helper functions * `maybe-print-cause' * `maybe-print-explanation' * `print-reference' Macros * `with-condition-translation' * `define-condition-translating-method' * `error-behavior-restart-cases'

README:

FUNCTION

Public

INCOMPATIBLE-ARGUMENTS (&REST ARGUMENTS)

Signal an `incompatible-arguments' error for ARGUMENTS which has to be of the form PARAMETER1 VALUE1 PARAMETER2 VALUE2 ...

INCOMPATIBLE-INITARGS (CLASS &REST INITARGS)

Signal an `incompatible-initargs' error for CLASS and INITARGS.

MAYBE-PRINT-CAUSE (STREAM CONDITION &OPTIONAL COLON? AT?)

Print the condition that caused CONDITION to be signaled (if any) onto STREAM.

MAYBE-PRINT-EXPLANATION (STREAM CONDITION &OPTIONAL COLON? AT?)

Format the message contained in the `simple-condition' CONDITION on STREAM. When COLON? is non-nil, the explanation is printed in an indented logical block.

MISSING-REQUIRED-ARGUMENT (PARAMETER)

Signal a `missing-required-argument' error for PARAMETER.

MISSING-REQUIRED-INITARG (CLASS INITARG)

Signal a `missing-required-initarg' error for CLASS and INITARG.

REFERENCE-DOCUMENT (SPEC)

Return the document of SPEC.

REFERENCE-PART (SPEC)

Return the part of SPEC.

Private

MACRO

Public

DEFINE-CONDITION-TRANSLATING-METHOD (NAME (&REST ARGS) &BODY CLAUSES)

Define a method on the generic function designated by NAME which translates conditions according to CLAUSES (For a description of CLAUSES, see `with-condition-translation').

ERROR-BEHAVIOR-RESTART-CASE ((VAR (ERROR-CONDITION &REST INITARGS &KEY &ALLOW-OTHER-KEYS) &KEY WARNING-CONDITION (ALLOW-OTHER-VALUES? T)) &BODY CLAUSES)

Select error/warning signaling of ERROR-CONDITION or WARNING-CONDITION according to VAR and establish restarts as specified in CLAUSES. CLAUSES use the same syntax as the restart clauses in `cl:restart-case'. INITARGS are passed to the constructed conditions. ALLOW-OTHER-VALUES? controls whether the form should evaluate to the value of VAR if it is not a function. Example: (flet ((try-policy (policy) (error-behavior-restart-case (policy (simple-error :format-control "Example error: ~A" :format-arguments (list :foo)) :warning-condition simple-warning :allow-other-values? t) (continue (&optional condition) :continue)))) ;; (try-policy #'error) => Error: Example error: FOO ;; (try-policy 'error) => Error: Example error: FOO (mapcar #'try-policy (list warn #'warn continue #'continue 1 :foo nil))) | WARNING: Example error: FOO | WARNING: Example error: FOO => (nil nil :continue :continue 1 :foo nil)

WITH-CONDITION-TRANSLATION (CLAUSES &BODY BODY)

Execute BODY translating conditions as specified by CLAUSES when they are signaled. CLAUSES is a list of clauses of the form ((FROM-CONDITION TO-CONDITION &key var cause-initarg signal-via muffle?) INITARG1 VALUE1 INITARG2 VALUE2 ...) FROM-CONDITION specifies a condition type (as e.g. in `cl:handler-bind') instances of which should be translated to instances of the condition class designated by TO-CONDITION. The instance of TO-CONDITIONS is signaled via the value of :SIGNAL-VIA (default is `cl:error') and receives the initargs INITARG1 VALUE1, INITARG2 VALUE2, ... and the value of :CAUSE-INITARG (default is :CAUSE) with the original condition instance as its value. When the value of :CAUSE-INITARG is nil, the original condition is not passed to the constructed condition instance. If supplied, the value of :VAR names a variable in which the original condition instance should be received. MUFFLE? controls whether the original condition should be muffled after the translation has been performed. (This is useful for `cl:warning's and generic `cl:condition's which would not get handled by resignaling via e.g. `cl:warn').

GENERIC-FUNCTION

Public

CAUSE (CONDITION)

Return the condition that was signaled and caused CONDITION to be signaled.

CONDITION-REFERENCES (CONDITION)

Return a list of references (of type `reference-spec') which are associated to CONDITION.

ROOT-CAUSE (CONDITION)

Return the condition that was originally signaled and eventually caused CONDITION to be signaled.

Undocumented

INCOMPATIBLE-ARGUMENTS-PARAMETERS (CONDITION)

INCOMPATIBLE-ARGUMENTS-VALUES (CONDITION)

INITARG-ERROR-CLASS (CONDITION)

MISSING-REQUIRED-ARGUMENT-PARAMETER (CONDITION)

VARIABLE

Public

*PRINT-REFERENCES*

When non-nil, `reference-condition' instances print reference information in addition to the primary condition report.

CONDITION

Public

CHAINABLE-CONDITION

Instances of this class can contain another condition instance which originally caused the condition to be signaled. This structure can continue recursively thus forming a chain of causing conditions.

INCOMPATIBLE-ARGUMENTS (&REST ARGUMENTS)

This error is signaled when an incompatible combination of arguments is supplied.

INCOMPATIBLE-INITARGS (CLASS &REST INITARGS)

This error is signaled when incompatible initargs are supplied.

INITARG-ERROR

This error is signaled when invalid initargs are supplied.

MISSING-REQUIRED-ARGUMENT (PARAMETER)

This error is signaled when no value is supplied for a required parameter.

MISSING-REQUIRED-INITARG (CLASS INITARG)

This error is signaled when an initarg that is required by a class is not supplied.

REFERENCE-CONDITION

This condition class is intended to be mixed into condition classes which can associate documentation references to their instances.