Skip to content

@graphty/graphty-element / index / GraphtyError

Class: GraphtyError ​

Defined in: graphty-element/src/errors/GraphtyError.ts:144

The error every graphty-element failure arrives as.

It is an ordinary Error, so instanceof Error, try/catch, await, .stack and a console log all behave the way a stranger expects. What it adds is the part a program can act on: a stable code, the source area that failed, whether retrying could help, and a structured details bag carrying the facts -- the name that was wrong and the names that would have been right, the estimate and the cap, the url and the status.

Codes cross module and worker boundaries; classes do not. A sibling package's error is re-reported through GraphtyError.wrap, which keeps the original as cause.

Example ​

ts
try {
    await session.layout.set("frce");
} catch (err) {
    if (isGraphtyError(err) && err.code === "E_UNKNOWN_LAYOUT") {
        showPicker(err.details.available);
    }
}

Extends ​

  • Error

Constructors ​

Constructor ​

new GraphtyError(init): GraphtyError

Defined in: graphty-element/src/errors/GraphtyError.ts:168

Builds an error.

Parameters ​

init ​

GraphtyErrorInit

The code, the message, the failing area and anything else known about the failure.

Returns ​

GraphtyError

Overrides ​

Error.constructor

Properties ​

code ​

readonly code: GraphtyErrorCode

Defined in: graphty-element/src/errors/GraphtyError.ts:149

The machine-readable reason. Switch on this; never on the message.


details ​

readonly details: Readonly<Record<string, unknown>>

Defined in: graphty-element/src/errors/GraphtyError.ts:158

The structured facts behind the failure. Frozen.


name ​

readonly name: string = "GraphtyError"

Defined in: graphty-element/src/errors/GraphtyError.ts:146

Always "GraphtyError".

Overrides ​

Error.name


recoverable ​

readonly recoverable: boolean

Defined in: graphty-element/src/errors/GraphtyError.ts:155

Whether the same call, unchanged, could succeed later.


source ​

readonly source: GraphtyErrorSource

Defined in: graphty-element/src/errors/GraphtyError.ts:152

The area of the element that failed.


target? ​

readonly optional target?: GraphtyErrorTarget

Defined in: graphty-element/src/errors/GraphtyError.ts:161

The run, layer or scope the failure belongs to, when it belongs to one.

Methods ​

toJSON() ​

toJSON(): GraphtyErrorJson

Defined in: graphty-element/src/errors/GraphtyError.ts:227

Renders the error as plain JSON.

Called by JSON.stringify, and used wherever an error has to survive a boundary a class cannot cross: a log line, a worker message, a bug report.

Returns ​

GraphtyErrorJson

The serialisable form.


wrap() ​

static wrap(cause, init): GraphtyError

Defined in: graphty-element/src/errors/GraphtyError.ts:198

Re-reports a failure from somewhere else as a GraphtyError.

A sibling package -- graph-io, graph-format, the WebGPU peer -- throws its own class. The class does not cross the boundary, so the element carries the code instead: when the original's code is one the element knows, that code wins; when it is a string the element does not know, it is kept in details.sourceCode and the caller's code is used. A value that is already a GraphtyError is returned untouched, so the most specific code survives.

Parameters ​

cause ​

unknown

The thrown value being wrapped.

init ​

Omit<GraphtyErrorInit, "cause" | "message"> & object

The code, area and facts to use when the original supplies none.

Returns ​

GraphtyError

The error to throw.