Condition Types

By convention, condition type names have a ^ prefix suggesting some higher level of intervention.

There is a predicate for each condition type, without the leading ^, and any fields have accessors called type-field.

The base condition type is ^condition and its immediate descendent is ^error.

Idio error types, ^idio-error, are descended from ^error and add three fields: message, location and detail.

A few instances of ^idio-error are still generated, largely from the C code base, but most conditions are instances of more specific condition types.

  • ^condition

    • ^error

      • ^idio-error (message location detail)

        • ^read-error (line position)

        • ^evaluation-error (expr)

        • ^string-error

        • ^static-error

          • ^static-variable-error (name)

            • ^static-variable-type-error

          • ^static-function-error

            • ^static-function-arity-error

        • ^i/o-error

          • ^i/o-handle-error (handle)

            • ^i/o-read-error

            • ^i/o-write-error

            • ^i/o-closed-error

          • ^i/o-filename-error (filename)

            • ^i/o-malformed-filename-error

            • ^i/o-file-protection-error

            • ^i/o-file-is-read-only-error

            • ^i/o-file-already-exists-error

            • ^i/o-no-such-file-error

          • ^i/o-mode-error (mode)

        • ^system-error (errno function)

        • ^runtime-error

          • ^rt-syntax-error

          • ^rt-parameter-error

            • ^rt-parameter-type-error

            • ^rt-const-parameter-error

            • ^rt-parameter-value-error

            • ^rt-parameter-nil-error

          • ^rt-variable-error (name)

            • ^rt-variable-unbound-error

            • ^rt-dynamic-variable-error

              • ^rt-dynamic--variable-unbound-error

            • ^rt-environ-variable-error

              • ^rt-environ--variable-unbound-error

            • ^rt-computed-variable-error

              • ^rt-computed--variable-no-accessor-error

          • ^rt-function-error

            • ^rt-function-arity-error

          • ^rt-module-error (module)

            • ^rt-module-unbound-error

            • ^rt-module-symbol-unbound-error (symbol)

          • ^rt-path-error (name)

          • ^rt-glob-error (pattern)

          • ^rt-command-error

            • ^rt-command-argv-type-error (arg)

            • ^rt-command-format-error (name value)

            • ^rt-command-env-type-error (name value)

            • ^rt-command-exec-error (errno)

            • ^rt-command-status-error (status)

              • ^rt-async-command-status-error

          • ^rt-array-error (index)

          • ^rt-hash-error

            • ^rt-hash-key-error (key)

          • ^rt-number-error (number)

            • ^rt-divide-by-zero-error

            • ^rt-bignum-error

              • ^rt-bignum-conversion-error

            • ^rt-C-conversion-error

            • ^rt-fixnum-error

              • ^rt-fixnum-conversion-error

          • ^rt-bitset-error

            • ^rt-bitset-bounds-error (bit)

            • ^rt-bitset-size-mismatch-error (size1 size2)

          • ^rt-keyword-error (keyword)

          • ^rt-libc-error

            • ^rt-libc-format-error (name)

          • ^rt-load-error (name)

          • ^rt-regex-error

          • ^rt-struct-error

          • ^rt-symbol-error

          • ^rt-vtable-unbound-error

          • ^rt-vtable-method-unbound-error (name)

          • ^rt-instance-error

          • ^rt-instance-invocation-error

          • ^rt-slot-not-found-error (slot)

          • ^rt-signal (signal)

Defining Condition Types

Defining condition types is slightly roundabout because most of the standard condition types are defined in C so that the C code can raise instances of the condition types.

Furthermore, the C code does not need accessor functions as it can access the internals of the condition types directly.

That said, the Idio code does need to have the accessor functions available otherwise it can’t access the condition internals.

From the C perspective, we have defined a condition type and we only need to have Idio define the predicate and accessors. This is done in lib/bootstrap/condition.idio with calls to define-condition-type-accessors-only.

From the Idio perspective, we need to define a condition type and then carry on with what the C condition types do.

So define-condition-type takes the condition type name and creates a standard predicate name and takes the field names and creates standard condition-name-field-name accessor names.

It then calls define-condition-type/accessors with these new names which creates the condition type and then calls define-condition-type-accessors-only as is done for the C condition types.

Condition Type Predicates

function condition-type? o

test if o is a condition type

Param o:

object to test

Return:

#t if o is a condition type #f otherwise

Condition Type Constructors

function make-condition-type name parent fields

make a new condition type

Param name:

condition type name

Type name:

symbol

Param parent:

parent condition type

Type parent:

#n or condition type

Param fields:

field names

Type fields:

list of symbols

Return:

new condition type

Rtype:

condition type

make a new condition type based on existing condition parent with fields fields

template define-condition-type name parent [fields]

generate default predicate and accessor names for define-condition-type/accessors

Param name:

condition name

Type name:

symbol

Param parent:

parent type

Type parent:

condition type

Param fields:

field data, defaults to #n

Type fields:

list, optional

Each field in fields should be a tuple of the form (field-name accessor-name).

Normally accessor-name would be condition-name-field-name.

template define-condition-type/accessors name parent predicate [fields]

define the condition then call define-condition-type-accessors-only

Param name:

condition name

Type name:

symbol

Param parent:

parent type

Type parent:

condition type

Param predicate:

predicate name

Type predicate:

symbol

Param fields:

field data, defaults to #n

Type fields:

list, optional

Each field in fields should be a tuple of the form (field-name accessor-name).

Normally accessor-name would be condition-name-field-name.

template define-condition-type-accessors-only name parent predicate [fields]

define the condition predicate and accessors

Param name:

condition name

Type name:

symbol

Param parent:

parent type

Type parent:

condition type

Param predicate:

predicate name

Type predicate:

symbol

Param fields:

field data, defaults to #n

Type fields:

list, optional

Each field in fields should be a tuple of the form (field-name accessor-name).

Normally accessor-name would be condition-name-field-name.

Condition Types Hierarchy

condition ^condition
function condition? o

test if o is a condition

Param o:

object to test

Return:

#t if o is a condition #f otherwise

condition ^error
Parent:

^condition

function error? arg/47
condition ^idio-error
Parent:

^error

Field:

message

Field:

location

Field:

detail

  • message

  • location

  • detail

function idio-error? arg/48
function idio-error-message arg/48
function idio-error-location arg/48
function idio-error-detail arg/48
condition ^read-error
Parent:

^idio-error

Field:

message

Field:

location

Field:

detail

Field:

line

Field:

position

function read-error? arg/61
function read-error-line arg/61
function read-error-position arg/61
condition ^evaluation-error
Parent:

^idio-error

Field:

message

Field:

location

Field:

detail

Field:

expr

function evaluation-error? arg/62
function evaluation-error-expr arg/62
condition ^string-error
Parent:

^idio-error

Field:

message

Field:

location

Field:

detail

function string-error? arg/63
condition ^static-error
Parent:

^idio-error

Field:

message

Field:

location

Field:

detail

function static-error? arg/65
condition ^st-variable-error
Parent:

^static-error

Field:

message

Field:

location

Field:

detail

Field:

name

function st-variable-error? arg/66
function st-variable-error-name arg/66
condition ^st-variable-type-error
Parent:

^st-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function st-variable-type-error? arg/67
condition ^st-function-error
Parent:

^static-error

Field:

message

Field:

location

Field:

detail

function st-function-error? arg/68
function st-function-arity-error? arg/69
condition ^st-function-arity-error
Parent:

^st-function-error

Field:

message

Field:

location

Field:

detail

condition ^i/o-error
Parent:

^idio-error

Field:

message

Field:

location

Field:

detail

function i/o-error? arg/49
condition ^i/o-handle-error
Parent:

^i/o-error

Field:

message

Field:

location

Field:

detail

Field:

handle

function i/o-handle-error? arg/50
function i/o-handle-error-handle arg/50
condition ^i/o-read-error
Parent:

^i/o-handle-error

Field:

message

Field:

location

Field:

detail

Field:

handle

function i/o-read-error? arg/51
condition ^i/o-write-error
Parent:

^i/o-handle-error

Field:

message

Field:

location

Field:

detail

Field:

handle

function i/o-write-error? arg/52
condition ^i/o-closed-error
Parent:

^i/o-handle-error

Field:

message

Field:

location

Field:

detail

Field:

handle

function i/o-closed-error? arg/53
condition ^i/o-filename-error
Parent:

^i/o-error

Field:

message

Field:

location

Field:

detail

Field:

filename

function i/o-filename-error? arg/54
function i/o-filename-error-filename arg/54
condition ^i/o-malformed-filename-error
Parent:

^i/o-filename-error

Field:

message

Field:

location

Field:

detail

Field:

filename

function i/o-malformed-filename-error? arg/56
condition ^i/o-file-protection-error
Parent:

^i/o-filename-error

Field:

message

Field:

location

Field:

detail

Field:

filename

function i/o-file-protection-error? arg/57
condition ^i/o-file-is-read-only-error
Parent:

^i/o-file-protection-error

Field:

message

Field:

location

Field:

detail

Field:

filename

function i/o-file-is-read-only-error? arg/58
condition ^i/o-file-already-exists-error
Parent:

^i/o-filename-error

Field:

message

Field:

location

Field:

detail

Field:

filename

function i/o-file-already-exists-error? arg/59
condition ^i/o-no-such-file-error
Parent:

^i/o-filename-error

Field:

message

Field:

location

Field:

detail

Field:

filename

function i/o-no-such-file-error? arg/60
condition ^i/o-mode-error
Parent:

^i/o-error

Field:

message

Field:

location

Field:

detail

Field:

mode

function i/o-mode-error? arg/55
function i/o-mode-error-mode arg/55
condition ^system-error
Parent:

^idio-error

Field:

message

Field:

location

Field:

detail

Field:

errno

Field:

function

Field:

args

function system-error? arg/64
function system-error-errno arg/64
function system-error-function arg/64
condition ^runtime-error
Parent:

^idio-error

Field:

message

Field:

location

Field:

detail

function runtime-error? arg/70
condition ^rt-syntax-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-syntax-error? arg/71
condition ^rt-parameter-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-parameter-error? arg/72
condition ^rt-parameter-type-error
Parent:

^rt-parameter-error

Field:

message

Field:

location

Field:

detail

function rt-parameter-type-error? arg/73
condition ^rt-const-parameter-error
Parent:

^rt-parameter-error

Field:

message

Field:

location

Field:

detail

function rt-const-parameter-error? arg/74
condition ^rt-parameter-value-error
Parent:

^rt-parameter-error

Field:

message

Field:

location

Field:

detail

function rt-parameter-value-error? arg/75
condition ^rt-parameter-nil-error
Parent:

^rt-parameter-value-error

Field:

message

Field:

location

Field:

detail

function rt-parameter-nil-error? arg/76
condition ^rt-variable-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-variable-error? arg/77
function rt-variable-error-name arg/77
condition ^rt-variable-unbound-error
Parent:

^rt-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-variable-unbound-error? arg/78
condition ^rt-dynamic-variable-error
Parent:

^rt-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-dynamic-variable-error? arg/79
condition ^rt-dynamic-variable-unbound-error
Parent:

^rt-dynamic-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-dynamic-variable-unbound-error? arg/80
condition ^rt-environ-variable-error
Parent:

^rt-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-environ-variable-error? arg/81
condition ^rt-environ-variable-unbound-error
Parent:

^rt-environ-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-environ-variable-unbound-error? arg/82
condition ^rt-computed-variable-error
Parent:

^rt-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-computed-variable-error? arg/83
condition ^rt-computed-variable-no-accessor-error
Parent:

^rt-computed-variable-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-computed-variable-no-accessor-error? arg/84
condition ^rt-function-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-function-error? arg/85
condition ^rt-function-arity-error
Parent:

^rt-function-error

Field:

message

Field:

location

Field:

detail

function rt-function-arity-error? arg/86
condition ^rt-module-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

module

function rt-module-error? arg/87
function rt-module-error-module arg/87
condition ^rt-module-unbound-error
Parent:

^rt-module-error

Field:

message

Field:

location

Field:

detail

Field:

module

function rt-module-unbound-error? arg/88
condition ^rt-module-symbol-unbound-error
Parent:

^rt-module-error

Field:

message

Field:

location

Field:

detail

Field:

module

Field:

symbol

function rt-module-symbol-unbound-error? arg/89
function rt-module-symbol-unbound-error-symbol arg/89
condition ^rt-path-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

pathname

function rt-path-error? arg/90
function rt-path-error-pathname arg/90
condition ^rt-glob-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

pattern

function rt-glob-error? arg/91
function rt-glob-error-pattern arg/91
condition ^rt-command-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-command-error? arg/92
condition ^rt-command-argv-type-error
Parent:

^rt-command-error

Field:

message

Field:

location

Field:

detail

Field:

arg

function rt-command-argv-type-error? arg/93
function rt-command-argv-type-error-arg arg/93
condition ^rt-command-format-error
Parent:

^rt-command-error

Field:

message

Field:

location

Field:

detail

Field:

name

Field:

value

function rt-command-format-error? arg/94
function rt-command-format-error-name arg/94
function rt-command-format-error-value arg/94
condition ^rt-command-env-type-error
Parent:

^rt-command-error

Field:

message

Field:

location

Field:

detail

Field:

name

Field:

value

function rt-command-env-type-error? arg/95
function rt-command-env-type-error-name arg/95
function rt-command-env-type-error-value arg/95
condition ^rt-command-exec-error
Parent:

^rt-command-error

Field:

message

Field:

location

Field:

detail

Field:

errno

function rt-command-exec-error? arg/96
function rt-command-exec-error-errno arg/96
condition ^rt-command-status-error
Parent:

^rt-command-error

Field:

message

Field:

location

Field:

detail

Field:

status

  • location is set to be the job that failed such that you might:

    job := idio-error-location c
    format-job-detail job
    
  • status is the Unix status value

    You will need to use the libc functions libc/WIFEXITED, libc/WEXITSTATUS etc. to decode it.

function rt-command-status-error? arg/97
function rt-command-status-error-status arg/97
condition ^rt-async-command-status-error
Parent:

^rt-command-status-error

Field:

message

Field:

location

Field:

detail

Field:

status

  • location is set to be the job that failed such that you might:

    job := idio-error-location c
    format-job-detail job
    
  • status is the Unix status value

    You will need to use the libc functions libc/WIFEXITED, libc/WEXITSTATUS etc. to decode it.

function rt-async-command-status-error? arg/98
condition ^rt-array-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

index

function rt-array-error? arg/99
function rt-array-error-index arg/99
condition ^rt-hash-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-hash-error? arg/100
condition ^rt-hash-key-not-found-error
Parent:

^rt-hash-error

Field:

message

Field:

location

Field:

detail

Field:

key

function rt-hash-key-not-found-error? arg/101
function rt-hash-key-not-found-error-key arg/101
condition ^rt-number-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

number

function rt-number-error? arg/102
function rt-number-error-number arg/102
condition ^rt-divide-by-zero-error
Parent:

^rt-number-error

Field:

message

Field:

location

Field:

detail

Field:

number

function rt-divide-by-zero-error? arg/103
condition ^rt-bignum-error
Parent:

^rt-number-error

Field:

message

Field:

location

Field:

detail

Field:

number

function rt-bignum-error? arg/104
condition ^rt-bignum-conversion-error
Parent:

^rt-bignum-error

Field:

message

Field:

location

Field:

detail

Field:

number

function rt-bignum-conversion-error? arg/105
condition ^rt-C-conversion-error
Parent:

^rt-number-error

Field:

message

Field:

location

Field:

detail

Field:

number

function rt-C-conversion-error? arg/106
condition ^rt-fixnum-error
Parent:

^rt-number-error

Field:

message

Field:

location

Field:

detail

Field:

number

function rt-fixnum-error? arg/107
condition ^rt-fixnum-conversion-error
Parent:

^rt-fixnum-error

Field:

message

Field:

location

Field:

detail

Field:

number

function rt-fixnum-conversion-error? arg/108
condition ^rt-bitset-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-bitset-error? arg/109
condition ^rt-bitset-bounds-error
Parent:

^rt-bitset-error

Field:

message

Field:

location

Field:

detail

Field:

bit

function rt-bitset-bounds-error? arg/110
function rt-bitset-bounds-error-bit arg/110
condition ^rt-bitset-size-mismatch-error
Parent:

^rt-bitset-error

Field:

message

Field:

location

Field:

detail

Field:

size1

Field:

size2

function rt-bitset-size-mismatch-error? arg/111
function rt-bitset-size-mismatch-error-size1 arg/111
function rt-bitset-size-mismatch-error-size2 arg/111
condition ^rt-keyword-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

keyword

function rt-keyword-error? arg/112
function rt-keyword-error-keyword arg/112
condition ^rt-libc-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-libc-error? arg/113
condition ^rt-libc-format-error
Parent:

^rt-libc-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-libc-format-error? arg/114
function rt-libc-format-error-name arg/114
condition ^rt-load-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

filename

function rt-load-error? arg/118
function rt-load-error-filename arg/118
condition ^rt-regex-error
Parent:

^rt-libc-error

Field:

message

Field:

location

Field:

detail

function rt-regex-error? arg/115
condition ^rt-struct-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-struct-error? arg/116
condition ^rt-symbol-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-symbol-error? arg/117
condition ^rt-signal
Parent:

^error

Field:

signum

function rt-signal? arg/124
function rt-signal-signal arg/124
condition ^rt-vtable-unbound-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-vtable-unbound-error? arg/119
condition ^rt-vtable-method-unbound-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

Field:

name

function rt-vtable-method-unbound-error? arg/120
function rt-vtable-method-unbound-error-name arg/120
condition ^rt-instance-error
Parent:

^runtime-error

Field:

message

Field:

location

Field:

detail

function rt-instance-error? arg/121
condition ^rt-instance-invocation-error
Parent:

^rt-instance-error

Field:

message

Field:

location

Field:

detail

function rt-instance-invocation-error? arg/122
condition ^rt-slot-not-found-error
Parent:

^rt-instance-error

Field:

message

Field:

location

Field:

detail

Field:

slot

function rt-slot-not-found-error? arg/123
function rt-slot-not-found-error-slot arg/123

Condition Instances

Condition instances are struct instances whose types are descended from ^condition.

Condition Instance Predicates

function condition-isa? c ct

test if condition c is a condition type ct

Param c:

condition to test

Type c:

condition

Param ct:

condition type to assert

Type ct:

condition type

Return:

#t if c is a condition type ct, #f otherwise

Condition Instance Constructors

function make-condition ct values

initialize a condition of condition type ct with values values

Param ct:

condition type to allocate

Type ct:

condition type

Param values:

initial values for condition fields

Type values:

list

Return:

allocated condition

Rtype:

struct-instance

function allocate-condition ct

allocate a condition of condition type ct

Param ct:

condition type to allocate

Type ct:

condition type

Return:

allocated condition

Rtype:

struct-instance

The allocated condition will have fields set to #n

Used with condition.

template condition type [field-bindings]

allocate-condition an instance of condition type and condition-set! the supplied field-bindings

Param type:

condition type name

Type type:

symbol

Param field-bindings:

field data, defaults to #n

Type field-bindings:

list, optional

Each field in field-bindings should be a tuple of the form (field-name value).

condition is only used in testing.

Condition Instance Accessors

function condition-ref c field

return field field of condition c

Param c:

condition

Type c:

struct-instance

Param field:

field to return

Return:

field field of c

function condition-set! c field value

set field field of condition c to value value

Param c:

condition

Type c:

struct-instance

Param field:

field to set

Type field:

symbol

Param value:

value to set

Return:

#<unspec>

Condition Instance Functions

function condition-report prefix c [args]

print a report on condition c

Param prefix:

a distinguishing string

Type prefix:

string

Param c:

the condition

Type c:

condition instance

Param handle:

print to handle, defaults to current error handle

Type handle:

handle, optional

Return:

#<unspec>

The form of the report is not fixed and should not be relied upon.

Most reports are a single line but some, notably for ^rt-command-status-error, may be multiple lines.

function condition-report-extend ct cb

extend condition-report to handle condition type ct

Param ct:

condition type

Type ct:

condition type

Param cb:

callback handler

Type cb:

3-ary function

Return:

#<unspec>

cb will be invoked as cb c iem cr-printf where c is the condition instance, iem adds the standard ^idio-error information to the report and cr-printf is a printf-like function to add more information to the report.

Last built at 2024-12-21T07:10:37Z+0000 from 62cca4c (dev) for Idio 0.3.b.6