TypeScript / JavaScript

Errors guide

Examples and practical guidance for the JavaScript and TypeScript MaelysDatalogError API.

The MaelysDatalogError reference contains the complete class and method cards.

Usage and examples

engine.limits describes build bounds. maxPolicyAtoms and maxPolicyAtomBytes bound the policy vocabulary; they are separate from rules.programCounts(), session quotas and current input occupancy.

Separate answers from failures

OutcomeApplication meaning
containsFact(...) returns falseA valid query has no matching fact
TypeError or RangeErrorA JavaScript value or option fails wrapper validation
MaelysDatalogErrorAn engine operation or binding lifecycle requirement failed
An explanation returns status=truncatedA bounded document was returned successfully

Handle failures at the operation boundary, and release resources through finally even when reporting an error:

CODE
import { MaelysDatalogError, Status } from '@maelys-dev/datalog/wasm'

try {
  const result = session.solve(input)
  try {
    console.log(result.containsFact('allow', ['alice', 'roadmap.pdf']))
  } finally {
    result.close()
  }
} catch (error) {
  if (error instanceof MaelysDatalogError) {
    const d = error.diagnostic
    console.error(error.status, d.codeName, d.message)
    if (error.status === Status.PAYLOAD_TOO_LARGE && d.capacity) {
      console.error(d.capacity.observed, d.capacity.limit)
    }
  }
  throw error
}

The diagnostic is a copied immutable snapshot. Its optional location, predicate, capacity and other sections may coexist; read them only when present. Later operations do not overwrite an earlier error's diagnostic.

Correct the cause before retrying

StatusTypical corrective action
INVALID_STATECheck closed owners, a live result on the session, or an EDB still frozen after a successful solve
PAYLOAD_TOO_LARGEInspect the reported capacity and choose an admissible request or suitable new resource capacities
STORAGE_TOO_SMALLTreat insufficient workspace/storage as an operation failure, not as a successfully truncated document
UNSUPPORTEDCheck the selected runtime and backend, such as a filesystem path in WASM or a nonzero reference-backend work limit
NOT_FOUNDCheck the requested policy or result symbol; explanation symbol lookup is stricter than a negative membership query
FORBIDDENCheck manifest loading permissions rather than enabling them implicitly

engine.limits gives the profile's compiled bounds, input.usage reports current input occupancy, and session.capacities gives the session's chosen quotas. They answer different questions. Creating a LARGE Engine does not migrate an existing SMALL Engine's resources, and WASM memory growth does not make solver capacities unbounded.