IF Commons GitHub

errors

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-system FR-001

The errors the runtime throws (commons 0001-system FR-001): one class for each kind a caller acts on, by plain names (errors.NotFound), each made from the code Node gives (ENOENT, EEXIST, EACCES, ...), keeping that code, the path or address where there is one, and the original error as its cause. The runtime throws; Result belongs to the layers above, which turn these into their own errors.

import { errors } from "./errors.ts";
import { readTextFile } from "./fs.ts";
try {
  await readTextFile("/no/such/file");
} catch (e) {
  if (e instanceof errors.NotFound) console.log("not there");
  else throw e;
}

Source: commons/system/src/errors.ts

3 of 27 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

errorsconst
const errors: { readonly RuntimeError: typeof RuntimeError; readonly NotFound: typeof NotFound; readonly AlreadyExists: … (969 characters)
const errors: { readonly RuntimeError: typeof RuntimeError; readonly NotFound: typeof NotFound; readonly AlreadyExists: typeof AlreadyExists; readonly PermissionDenied: typeof PermissionDenied; readonly IsADirectory: typeof IsADirectory; readonly NotADirectory: typeof NotADirectory; readonly DirectoryNotEmpty: typeof DirectoryNotEmpty; readonly FilesystemLoop: typeof FilesystemLoop; readonly Busy: typeof Busy; readonly AddrInUse: typeof AddrInUse; readonly AddrNotAvailable: typeof AddrNotAvailable; readonly ConnectionRefused: typeof ConnectionRefused; readonly ConnectionReset: typeof ConnectionReset; readonly ConnectionAborted: typeof ConnectionAborted; readonly BrokenPipe: typeof BrokenPipe; readonly TimedOut: typeof TimedOut; readonly Interrupted: typeof Interrupted; readonly NetworkUnreachable: typeof NetworkUnreachable; readonly InvalidData: typeof InvalidData; readonly NotSupported: typeof NotSupported; readonly UnexpectedEof: typeof UnexpectedEof; }

The error classes by name.

Imported by 48 tests of the run (48 passed, 0 failed): the library's results

mapErrorfunction
function mapError(thrown: unknown, path?: string | undefined): Error

What the host threw, as an error of the runtime: an error that carries a known code becomes its class (keeping the message, code, path and the original as its cause); any other Error, a runtime error among them, is returned as it is; anything else is wrapped by toError.

Imported by 7 tests of the run (7 passed, 0 failed): the library's results

RuntimeErrorclass
class RuntimeError extends Error

What every error of the runtime carries: the code the host gave and, for a file or an address, where.

MemberTypeWhat it is
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
messagestring
stack?string

Imported by 7 tests of the run (7 passed, 0 failed): the library's results

toErrorfunctionno test imports it
function toError(thrown: unknown, message?: string): Error

What was thrown or rejected, as an Error: an Error as it is, anything else wrapped, kept as the cause.

NotFoundclassno test imports it
class NotFound extends RuntimeError

Nothing is at the path, or no such program (ENOENT).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
AlreadyExistsclassno test imports it
class AlreadyExists extends RuntimeError

Something is already at the path (EEXIST).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
PermissionDeniedclassno test imports it
class PermissionDenied extends RuntimeError

The account may not do this (EACCES, EPERM).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
IsADirectoryclassno test imports it
class IsADirectory extends RuntimeError

A folder was given where a file was needed (EISDIR).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
NotADirectoryclassno test imports it
class NotADirectory extends RuntimeError

A file was given where a folder was needed (ENOTDIR).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
DirectoryNotEmptyclassno test imports it
class DirectoryNotEmpty extends RuntimeError

A folder that must be empty is not (ENOTEMPTY).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
FilesystemLoopclassno test imports it
class FilesystemLoop extends RuntimeError

Links point at each other with no end (ELOOP).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
Busyclassno test imports it
class Busy extends RuntimeError

The resource is in use (EBUSY, ETXTBSY).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
AddrInUseclassno test imports it
class AddrInUse extends RuntimeError

The address is already in use (EADDRINUSE).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
AddrNotAvailableclassno test imports it
class AddrNotAvailable extends RuntimeError

The address cannot be used on this computer (EADDRNOTAVAIL).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
ConnectionRefusedclassno test imports it
class ConnectionRefused extends RuntimeError

Nothing listens at the address (ECONNREFUSED).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
ConnectionResetclassno test imports it
class ConnectionReset extends RuntimeError

The other end reset the connection (ECONNRESET).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
ConnectionAbortedclassno test imports it
class ConnectionAborted extends RuntimeError

The connection was aborted (ECONNABORTED).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
BrokenPipeclassno test imports it
class BrokenPipe extends RuntimeError

The other end of a pipe was closed (EPIPE).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
TimedOutclassno test imports it
class TimedOut extends RuntimeError

The call took too long (ETIMEDOUT).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
Interruptedclassno test imports it
class Interrupted extends RuntimeError

A signal interrupted the call (EINTR).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
NetworkUnreachableclassno test imports it
class NetworkUnreachable extends RuntimeError

The network cannot be reached (ENETUNREACH, EHOSTUNREACH).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
InvalidDataclassno test imports it
class InvalidData extends RuntimeError

The data was not what was expected (EINVAL on data, a bad archive or encoding).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
NotSupportedclassno test imports it
class NotSupported extends RuntimeError

This platform or file system cannot do it (ENOSYS, ENOTSUP, EXDEV across devices).

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
UnexpectedEofclassno test imports it
class UnexpectedEof extends RuntimeError

The end of the data came before what was needed.

MemberTypeWhat it is
messagestring
stack?string
cause?unknown
codestringThe host's error code (ENOENT, EACCES, ...), or "" where it gave none.
pathstring | undefinedThe path, or the address, the failed call was about, where there was one.
namestringThe class's own name, so a stack trace says NotFound and not Error.
BY_CODEconstno test imports it
const BY_CODE: Readonly<Record<string, ErrorClass>>

The class each Node error code becomes.

hostCallfunctionno test imports it
function hostCall<T>(path: string | undefined, f: () => Promise<T>): Promise<T>

Run a call on the host and throw what it throws as an error of the runtime.

hostCallSyncfunctionno test imports it
function hostCallSync<T>(path: string | undefined, f: () => T): T

The same, for a call that does not wait.

Titles, headings, exports, tables, columns and requirements. Esc closes.