Ports, Error Handling - r3n/rebol-wiki GitHub Wiki

Types of Port Errors

When using a port, different types of errors can happen, and the type determines how the error is processed.

  • Actor error - there is an error in port function that is being called. These errors will cause an immediate error condition, printing an error message (or caught by your program's exception handling code). Possible cases may be:
    • Port not open
    • Action not found (port actor does not support it)
    • Bad data for action (e.g. wrong datatype or size)
    • Invalid port state (e.g. port is not ready)
  • Port error - a problem happened in making a network connection or during data transfer. These also cause an immediate error. Possible examples are:
    • Cannot open the specified address
    • Sever closed the connection
    • Connection interrupted
    • Timeout
    • Checksum or validation error
  • Content error - the content itself indicates an error. The connection and transfer were fine, but the result from the server indicated a problem. These may or may not cause an error depending on options (specs) provided to the port. Also, many lower level ports are just transport layers and do not care about application layer errors.
    • Invalid request
    • Target was not found (e.g. missing file)
    • Access denied
    • File locked

Error Handling

Depending on the type of error, the AWAKE handler for the port will get called. The event type is ERROR and the event/code field will hold an integer to indicate the raw error type. (We may want to expand this.)

Note that the error will de-queue the lower-level pending request and no more will be done for it. If you want to re-start an action, you must do it again, just like you would for read and write.

We need a list of possible error codes (for event/code) and their meaning (does it map directly to the error! code field?) --Gabriele 02:33, 19 June 2007 (EDT)

Code to spoof an error for testing

It is difficult to actually generate test errors (because TCP relies on timeouts for those kinds of cases) so here's how to spoof a TCP error for testing in the alpha release:

p: open tcp://10.10.10.2
wait p ; wait for open to happen
p/awake: func [evt] [ ; now, take over events
    print ["Event:" evt/type]
    if evt/type = 'error [print ["Error code:" evt/code]]
]
delete p ; temp - spoof an error event
write p "test" ; force request to queue so error will be seen
wait [p 2] ; process error
close p
⚠️ **GitHub.com Fallback** ⚠️