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.
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
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
class RuntimeError extends Error What every error of the runtime carries: the code the host gave and, for a file or an address, where.
Member Type What it is cause?unknowncodestringThe 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. messagestringstack?string
Imported by 7 tests of the run (7 passed, 0 failed): the library's results
toErrorfunction no 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.
NotFoundclass no test imports it class NotFound extends RuntimeError Nothing is at the path, or no such program (ENOENT).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
AlreadyExistsclass no test imports it class AlreadyExists extends RuntimeError Something is already at the path (EEXIST).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
PermissionDeniedclass no test imports it class PermissionDenied extends RuntimeError The account may not do this (EACCES, EPERM).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
IsADirectoryclass no test imports it class IsADirectory extends RuntimeError A folder was given where a file was needed (EISDIR).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
NotADirectoryclass no test imports it class NotADirectory extends RuntimeError A file was given where a folder was needed (ENOTDIR).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
DirectoryNotEmptyclass no test imports it class DirectoryNotEmpty extends RuntimeError A folder that must be empty is not (ENOTEMPTY).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
FilesystemLoopclass no test imports it class FilesystemLoop extends RuntimeError Links point at each other with no end (ELOOP).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
Busyclass no test imports it class Busy extends RuntimeError The resource is in use (EBUSY, ETXTBSY).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
AddrInUseclass no test imports it class AddrInUse extends RuntimeError The address is already in use (EADDRINUSE).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
AddrNotAvailableclass no test imports it class AddrNotAvailable extends RuntimeError The address cannot be used on this computer (EADDRNOTAVAIL).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
ConnectionRefusedclass no test imports it class ConnectionRefused extends RuntimeError Nothing listens at the address (ECONNREFUSED).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
ConnectionResetclass no test imports it class ConnectionReset extends RuntimeError The other end reset the connection (ECONNRESET).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
ConnectionAbortedclass no test imports it class ConnectionAborted extends RuntimeError The connection was aborted (ECONNABORTED).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
BrokenPipeclass no test imports it class BrokenPipe extends RuntimeError The other end of a pipe was closed (EPIPE).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
TimedOutclass no test imports it class TimedOut extends RuntimeError The call took too long (ETIMEDOUT).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
Interruptedclass no test imports it class Interrupted extends RuntimeError A signal interrupted the call (EINTR).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
NetworkUnreachableclass no test imports it class NetworkUnreachable extends RuntimeError The network cannot be reached (ENETUNREACH, EHOSTUNREACH).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
InvalidDataclass no test imports it class InvalidData extends RuntimeError The data was not what was expected (EINVAL on data, a bad archive or encoding).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
NotSupportedclass no test imports it class NotSupported extends RuntimeError This platform or file system cannot do it (ENOSYS, ENOTSUP, EXDEV across devices).
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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.
UnexpectedEofclass no test imports it class UnexpectedEof extends RuntimeError The end of the data came before what was needed.
Member Type What it is messagestringstack?stringcause?unknowncodestringThe 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_CODEconst no test imports it const BY_CODE : Readonly <Record <string , ErrorClass >>The class each Node error code becomes.
hostCallfunction no 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.
hostCallSyncfunction no test imports it function hostCallSync <T >(path : string | undefined , f : () => T ): T The same, for a call that does not wait.