SysError

Usage

use SysError;

This module helps handle system errors.

This module defines the type syserr, which can encode an error code or error message and be returned from routines generating an error. Additional routines are provided to print a useful error message from a syserr.

The IO module uses these routines in a way that supports error inspection and rapid prototyping. Most routines in the IO module have two forms. In one form, an error (of type syserr) is returned in an out error argument. In the second form, no error is returned, and instead the task will halt with a fatal error if an error is encountered.

class SystemError: Error

SystemError is a base class for Errors generated from syserr. It provides factory methods to create different subtypes based on the syserr that is passed.

var err: syserr
var details: string
proc SystemError(err: syserr, details: string = "")
proc message()

Provides a formatted string output for SystemError, generated from the internal err and the details string.

proc writeThis(f)
proc type fromSyserr(err: syserr, details: string = "")

Return the matching SystemError subtype for a given syserr, with an optional string containing extra details.

Arguments:
  • err -- the syserr to generate from
  • details -- extra information to include with the error
proc type fromSyserr(err: int, details: string = "")

Return the matching SystemError subtype for a given error number, with an optional string containing extra details.

Arguments:
  • err -- the number to generate from
  • details -- extra information to include with the error
class BlockingIOError: SystemError

BlockingIOError is the subclass of SystemError corresponding to SysBasic.EAGAIN, SysBasic.EALREADY, SysBasic.EWOULDBLOCK, and SysBasic.EINPROGRESS.

proc BlockingIOError(details: string = "", err: syserr = EWOULDBLOCK)
class ChildProcessError: SystemError

ChildProcessError is the subclass of SystemError corresponding to SysBasic.ECHILD.

proc ChildProcessError(details: string = "", err: syserr = ECHILD)
class ConnectionError: SystemError

ConnectionError is the subclass of SystemError that serves as the base class for all system errors regarding connections.

class BrokenPipeError: ConnectionError

BrokenPipeError is the subclass of ConnectionError corresponding to SysBasic.EPIPE and SysBasic.ESHUTDOWN.

proc BrokenPipeError(details: string = "", err: syserr = EPIPE)
class ConnectionAbortedError: ConnectionError

ConnectionAbortedError is the subclass of ConnectionError corresponding to SysBasic.ECONNABORTED.

proc ConnectionAbortedError(details: string = "", err: syserr = ECONNABORTED)
class ConnectionRefusedError: ConnectionError

ConnectionRefusedError is the subclass of ConnectionError corresponding to SysBasic.ECONNREFUSED.

proc ConnectionRefusedError(details: string = "", err: syserr = ECONNREFUSED)
class ConnectionResetError: ConnectionError

ConnectionResetError is the subclass of ConnectionError corresponding to SysBasic.ECONNRESET.

proc ConnectionResetError(details: string = "", err: syserr = ECONNRESET)
class FileExistsError: SystemError

FileExistsError is the subclass of SystemError corresponding to SysBasic.EEXIST.

proc FileExistsError(details: string = "", err: syserr = EEXIST)
class FileNotFoundError: SystemError

FileNotFoundError is the subclass of SystemError corresponding to SysBasic.ENOENT.

proc FileNotFoundError(details: string = "", err: syserr = ENOENT)
class InterruptedError: SystemError

InterruptedError is the subclass of SystemError corresponding to SysBasic.EINTR.

proc InterruptedError(details: string = "", err: syserr = EINTR)
class IsADirectoryError: SystemError

IsADirectoryError is the subclass of SystemError corresponding to SysBasic.EISDIR.

proc IsADirectoryError(details: string = "", err: syserr = EISDIR)
class NotADirectoryError: SystemError

NotADirectoryError is the subclass of SystemError corresponding to SysBasic.ENOTDIR.

proc NotADirectoryError(details: string = "", err: syserr = ENOTDIR)
class PermissionError: SystemError

PermissionError is the subclass of SystemError corresponding to SysBasic.EACCES and SysBasic.EPERM.

proc PermissionError(details: string = "", err: syserr = EPERM)
class ProcessLookupError: SystemError

ProcessLookupError is the subclass of SystemError corresponding to SysBasic.ESRCH.

proc ProcessLookupError(details: string = "", err: syserr = ESRCH)
class TimeoutError: SystemError

TimeoutError is the subclass of SystemError corresponding to SysBasic.ETIMEDOUT.

proc TimeoutError(details: string = "", err: syserr = ETIMEDOUT)
class IOError: SystemError

IOError is the subclass of SystemError that serves as the base class for all errors regarding inputs and their formatting. They are typically not directly generated by the OS, but they are used and emitted by the IO module.

class EOFError: IOError

EOFError is the subclass of SystemError corresponding to SysBasic.EEOF.

proc EOFError(details: string = "", err: syserr = EEOF)
class UnexpectedEOFError: IOError

UnexpectedEOFError is the subclass of SystemError corresponding to SysBasic.ESHORT.

proc UnexpectedEOFError(details: string = "", err: syserr = ESHORT)
class BadFormatError: IOError

BadFormatError is the subclass of SystemError corresponding to SysBasic.EFORMAT.

proc BadFormatError(details: string = "", err: syserr = EFORMAT)
proc ioerror(error: syserr, msg: string) throws

Halt with a useful message if there was an error. Do nothing if the error argument does not indicate an error occurred. The error message printed when halting will describe the error passed and msg will be appended to it.

Arguments:
  • error -- the error object
  • msg -- extra information to print after the error description
proc ioerror(error: syserr, msg: string, path: string) throws

Halt with a useful message if there was an error. Do nothing if the error argument does not indicate an error occurred. The error message printed when halting will describe the error passed and msg will be appended to it, along with the path related to the error (for example, the path to a file which could not be opened).

Arguments:
  • error -- the error object
  • msg -- extra information to print after the error description
  • path -- a path to print out that is related to the error
proc ioerror(error: syserr, msg: string, path: string, offset: int(64)) throws

Halt with a useful message if there was an error. Do nothing if the error argument does not indicate an error occurred. The error message printed when halting will describe the error passed and msg will be appended to it, along with the path and file offset related to the error. For example, this routine might indicate a file format error at a particular location.

Arguments:
  • error -- the error object
  • msg -- extra information to print after the error description
  • path -- a path to print out that is related to the error
  • offset -- an offset to print out that is related to the error
proc ioerror(errstr: string, msg: string, path: string, offset: int(64)) throws

Halt with a useful message. Instead of an error argument, this routine takes in an error string to report. The error message printed when halting will describe the error passed and msg will be appended to it, along with the path and file offset related to the error. For example, this routine might indicate a file format error at a particular location.

This routine .

Arguments:
  • errstr -- the error string
  • msg -- extra information to print after the error description
  • path -- a path to print out that is related to the error
  • offset -- an offset to print out that is related to the error
proc errorToString(error: syserr): string

Convert a syserr error code to a human-readable string describing that error.

Arguments:errstr -- the error string
Returns:a string describing the error