chickadee » condition-utils

condition-utils

SRFI 12 Condition Utilities

TOC »

Documentation

Convenience API for constructing common Chicken exception conditions, predicates, and accessors.

Argument Conventions

LOC is a symbol, or #f.

MSG is a string, or #f.

ARGS is a list, or #f.

CALL-CHAIN is the result of (get-call-chain), or #f.

CONDITION is a property-condition.

KIND is usually a symbol but not #f.

PROP is usually a symbol but not #f.

CONDITION-SPEC is a:

CONDITION
a condition object
atom
(make-property-condition <atom>) ;see KIND
list
(apply make-property-condition <list>) ;(KIND PROP VALUE ...)

Condition Library

Usage

(import condition-utils)

make-condition+

make-condition+ CONDITION-SPEC...procedure

Returns a composite-condition CONDITION-SPEC....

make-condition-predicate

(make-condition-predicate KIND...) -> (procedure (*) boolean)syntax

Returns a condition-predicate for KIND....

KIND
symbol ;argument is quoted!

condition-predicate*

condition-predicate* KINDprocedure

Returns a "memoized" condition-predicate for KIND.

KIND
(not false) ;argument is evaluated

make-condition-property-accessor

(make-condition-property-accessor KIND PROP [DEFAULT]) -> (procedure (*) boolean)syntax

Returns a condition-property-accessor for KIND PROP. The default value of DEFAULT is #f.

KIND
symbol ;argument is quoted!
PROP
symbol ;argument is quoted!

condition-property-accessor*

(condition-property-accessor* KIND PROP [DEFAULT #f]) -> (condition -> *)procedure

Returns a "memoized" condition-property-accessor for KIND.

KIND
(not false) ;argument is evaluated
PROP
(not false) ;argument is evaluated

condition-irritants

condition-irritants CONDITIONprocedure

Returns a list of the condition properties for the condition CONDITION. The form of the list, alist vs. plist, is dependent on the result of the system procedure condition->list.

CHICKEN 4
alist
CHICKEN 5
plist

The properties are without associated condition information.

write-condition

(write-condition CONDITION [PORT (current-output-port) [HEADER "Error"]])procedure

Produces on PORT the form:

Error: <condition-kind>: <condition-property> ...

   +: <condition-kind>: <condition-property> ...
      ... for a composite condition ...

EXN Condition Library

Usage

(import exn-condition)

make-exn-condition

make-exn-condition #!optional LOC MSG ARGS CALL-CHAIN ERRNOprocedure

Returns an exn property-condition with optional location, arguments, call-chain, and errno property values.

Defaults:

LOC
missing
MSG
"unknown"
ARGS
missing
CALL-CHAIN
missing
ERRNO
missing

Will always include message property in the property-condition.

make-exn-condition*

(make-exn-condition* [location:] [message:] [arguments:] [call-chain:] [errno:]) -> property-conditionprocedure

Returns an exn property-condition with optional location, arguments, call-chain, and errno property values.

Defaults:

location
missing
message
"unknown"
arguments
missing
call-chain:
missing
errno
missing

Will always include message property in the property-condition.

make-exn-condition+

(make-exn-condition+ LOC MSG ARGS [CALL-CHAIN] [ERRNO] [CONDITION-SPEC...]) -> property-conditionprocedure

Returns a composite-condition exn CONDITION-SPEC....

When one-of LOC, MSG, or ARGS is without a useful value in the error context use #f as the actual argument. The optional CALL-CHAIN & ERRNO arguments are detected by type & structure.

When MSG is #f the value "unknown" is used.

write-exn-condition

(write-exn-condition CONDITION [PORT (current-output-port) [HEADER "Error" [CHAIN-HEADER "\n\tCall history:\n"]]])procedure

Produces on PORT the form:

Error: (<location - if any>) <message - if any>: <arguments - if any>

   +: <condition-kind>: <condition-property> ...
      ... for a composite condition ...
      Call history:
      <call-chain>

The call-chain may not be available.

exn-condition?
exn-condition? CONDITIONprocedure
exn-location
exn-location CONDITIONprocedure
exn-message
exn-message CONDITIONprocedure
exn-arguments
exn-arguments CONDITIONprocedure
exn-call-chain
exn-call-chain CONDITIONprocedure
exn-errno
exn-errno CONDITIONprocedure

Standard Condition Library

Usage

(import standard-conditions)

Condition Predicates

arity-condition?
arity-condition? CONDITIONprocedure
type-condition?
type-condition? CONDITIONprocedure
arithmetic-condition?
arithmetic-condition? CONDITIONprocedure
i/o-condition?
i/o-condition? CONDITIONprocedure
file-condition?
file-condition? CONDITIONprocedure
network-condition?
network-condition? CONDITIONprocedure
network-timeout-condition?
network-timeout-condition? CONDITIONprocedure
bounds-condition?
bounds-condition? CONDITIONprocedure
runtime-condition?
runtime-condition? CONDITIONprocedure
runtime-limit-condition?
runtime-limit-condition? CONDITIONprocedure
runtime-cycle-condition?
runtime-cycle-condition? CONDITIONprocedure
match-condition?
match-condition? CONDITIONprocedure
syntax-condition?
syntax-condition? CONDITIONprocedure
process-condition?
process-condition? CONDITIONprocedure
access-condition?
access-condition? CONDITIONprocedure
domain-condition?
domain-condition? CONDITIONprocedure
memory-condition?
memory-condition? CONDITIONprocedure

HTTP Client Condition Library

Usage

(import http-client-conditions)

Condition Predicates

http-condition?
http-condition? CONDITIONprocedure
client-error-condition?
client-error-condition? CONDITIONprocedure
server-error-condition?
server-error-condition? CONDITIONprocedure
unexpected-server-response-condition?
unexpected-server-response-condition? CONDITIONprocedure
redirect-depth-exceeded-condition?
redirect-depth-exceeded-condition? CONDITIONprocedure
unsupported-uri-scheme-condition?
unsupported-uri-scheme-condition? CONDITIONprocedure
unknown-authtype-condition?
unknown-authtype-condition? CONDITIONprocedure

Condition Property Accessors

client-error-response
client-error-response CONDITIONprocedure
client-error-body
client-error-body CONDITIONprocedure
server-error-response
server-error-response CONDITIONprocedure
server-error-body
server-error-body CONDITIONprocedure
unexpected-server-response-response
unexpected-server-response-response CONDITIONprocedure
unexpected-server-response-body
unexpected-server-response-body CONDITIONprocedure
redirect-depth-exceeded-uri
redirect-depth-exceeded-uri CONDITIONprocedure
formdata-error-condition?
formdata-error-condition? CONDITIONprocedure
unsupported-uri-scheme-uri-scheme
unsupported-uri-scheme-uri-scheme CONDITIONprocedure
unsupported-uri-scheme-request-uri
unsupported-uri-scheme-request-uri CONDITIONprocedure
unknown-authtype-authtype
unknown-authtype-authtype CONDITIONprocedure

Intarweb Condition Library

Usage

(import intarweb-conditions)

Condition Predicates

http-condition?
http-condition? CONDITIONprocedure
urlencoded-request-data-limit-exceeded?
urlencoded-request-data-limit-exceeded? CONDITIONprocedure
line-limit-exceeded?
line-limit-exceeded? CONDITIONprocedure
header-error?
header-error? CONDITIONprocedure
header-limit-exceeded?
header-limit-exceeded? CONDITIONprocedure
unknown-protocol-line?
unknown-protocol-line? CONDITIONprocedure
unknown-protocol?
unknown-protocol? CONDITIONprocedure
unknown-code?
unknown-code? CONDITIONprocedure
unknown-status?
unknown-status? CONDITIONprocedure
rfc1123-subparser?
rfc1123-subparser? CONDITIONprocedure
rfc850-subparser?
rfc850-subparser? CONDITIONprocedure
asctime-subparser?
asctime-subparser? CONDITIONprocedure
http-date-subparser?
http-date-subparser? CONDITIONprocedure
unencoded-header?
unencoded-header? CONDITIONprocedure
username-with-colon?
username-with-colon? CONDITIONprocedure

Condition Property Accessors

urlencoded-request-data-limit-exceeded-contents
urlencoded-request-data-limit-exceeded-contents CONDITIONprocedure
urlencoded-request-data-limit-exceeded-limit
urlencoded-request-data-limit-exceeded-limit CONDITIONprocedure
line-limit-exceeded-contents
line-limit-exceeded-contents CONDITIONprocedure
line-limit-exceeded-limit
line-limit-exceeded-limit CONDITIONprocedure
header-error-contents
header-error-contents CONDITIONprocedure
header-limit-exceeded-contents
header-limit-exceeded-contents CONDITIONprocedure
header-limit-exceeded-limit
header-limit-exceeded-limit CONDITIONprocedure
unknown-protocol-line-line
unknown-protocol-line-line CONDITIONprocedure
unknown-protocol-major
unknown-protocol-major CONDITIONprocedure
unknown-protocol-minor
unknown-protocol-minor CONDITIONprocedure
unknown-code-code
unknown-code-code CONDITIONprocedure
unknown-status-status
unknown-status-status CONDITIONprocedure
rfc1123-subparser-value?
rfc1123-subparser-value? CONDITIONprocedure
rfc850-subparser-value?
rfc850-subparser-value? CONDITIONprocedure
asctime-subparser-value?
asctime-subparser-value? CONDITIONprocedure
http-date-subparser-value?
http-date-subparser-value? CONDITIONprocedure
unencoded-header-value?
unencoded-header-value? CONDITIONprocedure
username-with-colon-value?
username-with-colon-value? CONDITIONprocedure

Condition Libraries w/ Runtime Lookup

Usage Example

(import (rename (standard-conditions memo) (get standard-conditions-get)))
(import (rename (intarweb-conditions memo) (get intarweb-conditions-get)))
(import (rename (http-client-conditions memo) (get http-client-conditions-get)))

(define unexpected-server-response-response (http-client-conditions-get 'unexpected-server-response-response)

Bugs & Limitations

Notes

Author

Kon Lovett

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/condition-utils

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Version history

2.3.1
Fix condition predicate & accessor caching.
2.3.0
Add errno & make-exn-condition*.
2.2.2
.
2.2.1
.
2.2.0
Add condition library runtime lookup get API.
2.1.4
.
2.1.3
.
2.1.2
.
2.1.1
.
2.1.0
CHICKEN 5 release.
1.5.1
Fix for empty call-chain.
1.5.0
Add types.
1.4.2
Fix #1378
1.4.1
Fix write-exn-condition call-chain header duplication.
1.4.0
Add HEADER to write-exn-condition & write-condition. Add CHAIN-HEADER to write-exn-condition. Follow error form more closely.
1.3.0
write-exn-condition now includes all elements of a composite-condition. Added write-condition.
1.2.0
amended write-exn-condition, add doc for condition libraries.
1.1.1
added write-exn-condition
1.1.0
added make-exn-condition
1.0.4
default exn msg
1.0.3
added call-chain argument & standard conditions
1.0.2
Fix for ticket #630
1.0.1
1.0.0
Hello (from "check-errors:1.11.0")

License

Copyright (C) 2009-2024 Kon Lovett. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contents »