Errors

Error functions and constants.

/**
 * ES2020 only specifies an optional,
 * unknown `cause` property, 
while earlier
 * specs insist on name and message
 * strings.
 */
interface BaseError 
extends Partial<Error> {
  cause?: unknown
  message?: string
  name?: string
}
type ErrorCause = BaseError | PrimitiveOrUndefined | unknown
type ErrorName = string
interface Errored  {
  data?: undefined
  error: NamedError
}
/** Error that has been caught or generated. */
interface NamedError  {
  cause?: NamedError | string
  message: string
  name: ErrorName
}
interface RFC7807Error  {
  cause?: NamedError
  /**
   * a human-readable explanation specific to
   * this occurrence of the problem
   */
  detail: string
  /**
   * A URI that identifies the specific
   * occurrence of the problem. This might be
   * a path to the resource that caused the
   * error (e.g., /orders/12345) or a link to
   * a log entry
   */
  instance: string
  /**
   * The HTTP status code for this occurrence
   * of the problem
   */
  status: number
  /**
   * short, human-readable summary of the
   * problem type
   */
  title: string
  type: string
}
/**
 * Error that is safe to return from
 * server.
 */
interface ResponseError 
extends NamedError {
  cause?: NamedError | string
  message: string
  name: ErrorName
}
interface ResponseErrored 
extends Errored {
  data?: undefined
  error: NamedError
}
function createErrored(
  name: ErrorName, 
  message?: string, 
  cause?: unknown
): Errored
function createRFC7807Error(
  cause: NamedError, 
  id?: string
): RFC7807Error
/**
 * Handles low-level error that's been
 * caught, converting to Errored object.
 */
function erroredFromCaught(
  caughtError: unknown, 
  message: string
): Errored
function erroredResponse(
  error: unknown, 
  message: string
): ResponseErrored
/** Type guard for Errored */
function isErrored(
  value: unknown
): boolean
/** Type guard for NamedError */
function isNamedError(
  value: unknown
): boolean
function svgError(
  id: string, 
  size: Rect<number> | Size<number>, 
  outputSize: Size<number>, 
  errorName?: ErrorName, 
  foreColor?: string, 
  backColor?: string
): SvgItem
function throwAssert(
  value: unknown, 
  type: string, 
  property?: string, 
  cause?: unknown
): never
const ERROR_ARGUMENT = 'error.argument'
const ERROR_ASSERT = 'error.assert'
const ERROR_AUTH = 'error.auth'
const ERROR_CONFIG = 'error.config'
const ERROR_INTERNAL = 'error.internal'
const ERROR_PERMS = 'error.perms'
const ERROR_RANGE = 'error.range'
const ERROR_REFERENCE = 'error.reference'
const ERROR_SYNTAX = 'error.syntax'
const ERROR_TYPE = 'error.type'
const ERROR_UNAVAILABLE = 'error.unavailable'
const ERROR_UNIMPLEMENTED = 'error.unimplemented'
const ERROR_URL = 'error.url'