Skip to content

This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.

EngineError

Defined in: packages/engine/src/errors/EngineError.ts:97

The engine’s structured error type. Still a real Error subclass (so throw/catch/instanceof Error all keep working exactly as before), but now every field except the removed severity/recovery pair is something real code reads.

  • Error
new EngineError(category, init): EngineError;

Defined in: packages/engine/src/errors/EngineError.ts:144

ParameterType
categoryErrorCategory
initEngineErrorInit

EngineError

Error.constructor
readonly category: ErrorCategory;

Defined in: packages/engine/src/errors/EngineError.ts:98


readonly optional cause?: unknown;

Defined in: packages/engine/src/errors/EngineError.ts:117

Set explicitly (not via super(message, {cause})). This repo’s tsconfig.json targets ES6/ES5-ES7 lib, which predates TypeScript’s ES2022 Error constructor cause-option overload. Error.prototype.cause is still a real runtime feature in every target this engine actually runs in (Node 16.9+, all evergreen browsers, Electron/Obsidian’s bundled Chromium) regardless of the TS lib target used to type-check against it, assigning it directly gets the same Node-printer/logger interop with no build-config change needed.


readonly code: string;

Defined in: packages/engine/src/errors/EngineError.ts:99


readonly optional context?: Record<string, unknown>;

Defined in: packages/engine/src/errors/EngineError.ts:105


readonly optional expected?: string;

Defined in: packages/engine/src/errors/EngineError.ts:100


readonly optional found?: string;

Defined in: packages/engine/src/errors/EngineError.ts:101


message: string;

Defined in: docs/node_modules/typescript/lib/lib.es5.d.ts:1075

Error.message

name: string;

Defined in: docs/node_modules/typescript/lib/lib.es5.d.ts:1074

Error.name

readonly recoverable: boolean;

Defined in: packages/engine/src/errors/EngineError.ts:103


readonly optional span?: SourceSpan;

Defined in: packages/engine/src/errors/EngineError.ts:104


optional stack?: string;

Defined in: docs/node_modules/typescript/lib/lib.es5.d.ts:1076

Error.stack

readonly optional suggestion?: string;

Defined in: packages/engine/src/errors/EngineError.ts:102


readonly timestamp: Date;

Defined in: packages/engine/src/errors/EngineError.ts:106


static captureRecoverableStacks: boolean = false;

Defined in: packages/engine/src/errors/EngineError.ts:142

Whether a recoverable error captures a JavaScript stack trace.

Off, because a recoverable EngineError is a value rather than a fault. A line of prose in a notepad is not an expression, so parsing it fails, and that failure is the answer for that line rather than a bug to debug. The engine builds one such error per non-expression line.

Capturing a stack is not cheap, and its cost grows with how deep the stack is when it happens. Measured through parseDocument, where the throw site sits about a dozen frames down, each capture cost around 62 microseconds and a 250-line document built 74 of them: a CPU profile put the constructor at 46% of the whole pipeline, more than lexing, normalising, parsing and executing put together.

Turn it on to debug where a recoverable error is raised from. Errors that are NOT recoverable always capture, since those are the genuine faults.

EngineError.captureRecoverableStacks = true;

static stackTraceLimit: number;

Defined in: node_modules/@types/node/globals.d.ts:67

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Error.stackTraceLimit
causeChain(): unknown[];

Defined in: packages/engine/src/errors/EngineError.ts:187

Walk .cause repeatedly, collecting the full chain (this error first).

unknown[]


format(): string;

Defined in: packages/engine/src/errors/EngineError.ts:209

Rust/Go-style multi-line renderer, the NEW thing a host/CLI/test reaches for when it wants the full, verbose picture, as distinct from .message (kept short and stable for existing assertions). Example:

error[WEATHER_EXPECTED_CITY]: Expected a city name after "weather in"
expected: a city name
found: end of expression
suggestion: e.g. "weather in London"

string


isFatal(): boolean;

Defined in: packages/engine/src/errors/EngineError.ts:182

!recoverable. See EngineErrorInit.recoverable’s doc comment for what this actually gates (message framing/telemetry, not whether evaluation continues).

boolean


toJSON(): Record<string, unknown>;

Defined in: packages/engine/src/errors/EngineError.ts:217

Record<string, unknown>


static captureStackTrace(targetObject, constructorOpt?): void;

Defined in: node_modules/@types/node/globals.d.ts:51

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
ParameterType
targetObjectobject
constructorOpt?Function

void

Error.captureStackTrace

static prepareStackTrace(err, stackTraces): any;

Defined in: node_modules/@types/node/globals.d.ts:55

ParameterType
errError
stackTracesCallSite[]

any

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Error.prepareStackTrace