Class GeneralExpectedError

EXPECTED application-level condition — the Java-style Exception half of the error/exception split: "this failure is a known, anticipated business outcome, not a malfunction".

The framework does NOT pattern-match this class anywhere — it adds no special handling to gates, checks, or any other channel. It exists so APPLICATION code can split its own catch blocks the way Java splits Exception from Error:

  • GeneralExpectedError (and subclasses) — anticipated conditions the caller knows how to handle gracefully (validation failed, precondition not met, user-facing refusal with a meaningful message);
  • everything else — a genuine malfunction (отказ): bug, broken invariant, unexpected infrastructure failure. Treat as fatal for the current operation, log loudly, do not swallow.
try {
await doWork();
} catch (error) {
if (GeneralExpectedError.isGeneralExpectedError(error)) {
notifyUser(getErrorMessage(error)); // anticipated — handle and continue
return;
}
throw error; // malfunction — propagate as a failure
}

OrderRejectedError, OrderDeletedError and OrderTransientError are CHANNEL-specific verdicts consumed by the framework's order machinery. GeneralExpectedError is channel-agnostic and framework-invisible: throwing it from a gate or check is treated like any other non-typed throw (the "transient" verdict). Use the triad inside broker adapters; use GeneralExpectedError in your own application layers.

  • Nominal runtime identification. Recognized by the __type__ === Symbol.for("GeneralExpectedError") brand via the static guard — never by instanceof, so it survives duplicated module instances across bundles. Subclass it freely for domain-specific expected conditions: the brand is inherited, so the single guard catches the whole family.
  • The message is the user-facing payload — unlike the order triad, where the message is purely informational, here it typically carries the text shown to the human who triggered the operation.
class InsufficientBalanceError extends GeneralExpectedError {}

function assertBalance(balance: number, required: number) {
if (balance < required) {
throw new InsufficientBalanceError(
`insufficient balance: have ${balance}, need ${required}`
);
}
}

Hierarchy

  • Error
    • GeneralExpectedError

Constructors

Properties

__type__: symbol

Runtime brand (Symbol.for — survives duplicated module instances)

message: string
name: string
prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

Optional override for formatting stack traces

stack?: string
stackTraceLimit: number

Methods

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • OptionalconstructorOpt: Function

    Returns void

  • Nominal constructor for a new GeneralExpectedError from any thrown object. Use this instead of instanceof to recognize instances created by a DIFFERENT copy of this module (duplicated bundles, linked packages).

    Parameters

    • error: object

      Any thrown object

    Returns GeneralExpectedError

    a new GeneralExpectedError with the original message, or a default message if the original was not a string

  • Nominal type guard by the runtime brand. Use this instead of instanceof: the check is based on Symbol.for, so it recognizes instances created by a DIFFERENT copy of this module (duplicated bundles, linked packages), as well as any subclass carrying the inherited brand.

    Parameters

    • error: object

      Any thrown object

    Returns boolean

    true when the object carries the GeneralExpectedError brand