Class GeneralUnexpectedError

UNEXPECTED application-level malfunction — the Java-style Error half of the error/exception split: "this should never have happened; something is broken".

The framework does NOT pattern-match this class anywhere — it adds no special handling to gates, checks, or any other channel. It is the explicit counterpart of GeneralExpectedError: where that class marks anticipated business conditions the caller handles gracefully, this one marks genuine malfunctions (отказ) — a bug, a broken invariant, a state that the code was written to make impossible. Throw it where Java code would throw an Error / IllegalStateException:

  • GeneralExpectedError (and subclasses) — anticipated, handle and continue;
  • GeneralUnexpectedError (and everything untyped) — malfunction: abort the current operation, log loudly, never swallow.

Note the classification is asymmetric by design: an UNTYPED throw is already treated as a malfunction by the "everything not Expected is a failure" rule. This class therefore adds no new routing — it exists so a reader sees the intent spelled out at the throw site ("this branch is a broken invariant, not a forgotten classification"), mirroring how OrderTransientError makes the default verdict explicit in the order triad.

switch (position.side) {
case "long": return closeLong(position);
case "short": return closeShort(position);
default:
// Not a business outcome — a broken invariant. Deliberately unexpected.
throw new GeneralUnexpectedError(`unknown side: ${position.side}`);
}

OrderRejectedError, OrderDeletedError and OrderTransientError are CHANNEL-specific verdicts consumed by the framework's order machinery. GeneralUnexpectedError 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 GeneralUnexpectedError in your own application layers.

  • Nominal runtime identification. Recognized by the __type__ === Symbol.for("GeneralUnexpectedError") brand via the static guard — never by instanceof, so it survives duplicated module instances across bundles. Subclasses inherit the brand, so the single guard catches the whole family.
  • The message is diagnostic: it is written for the developer reading the log, not for the user who triggered the operation — the opposite of GeneralExpectedError, whose message is the user-facing payload.
try {
await doWork();
} catch (error) {
if (GeneralExpectedError.isGeneralExpectedError(error)) {
notifyUser(getErrorMessage(error)); // anticipated — handle and continue
return;
}
// GeneralUnexpectedError and any untyped throw land here — malfunction
logger.error("operation failed", error);
throw error;
}

Hierarchy

  • Error
    • GeneralUnexpectedError

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 GeneralUnexpectedError 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 GeneralUnexpectedError

    a new GeneralUnexpectedError 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 GeneralUnexpectedError brand