A remote failure is a typed error (TypeScript)¶
A request the node cannot satisfy is still answered, with FWD{REPLY, kind=ERROR} carrying
a STATUS{ERROR}. The client rejects with a FwdError whose .code is the registered wire
code.
The node on the other end is
stand-in-node.mjs,
an in-memory stand-in. The TypeScript packages have no node of their own, and the stand-in lets
the example run with no C++ build. Against a real node the client code is unchanged.
What to notice¶
NOT_FOUNDis0x0020.err.codeis the u16 from the wire anderr.codeNameits registry name, so a caller can branch on it.Failure is a reply, not a timeout. The promise rejects as soon as the error reply arrives.
Source¶
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
3
4/**
5 * @file
6 * @brief One concept: a remote failure is a reply, and the client surfaces it as a typed
7 * `FwdError` carrying the registered wire code — never as a hang or a bare string.
8 *
9 * Run: `node examples/remote-error.mjs` (from `bindings/typescript/`, after `npm run build`).
10 */
11
12import assert from 'node:assert/strict';
13import { LibtracerClient, FwdError, FWD_ERROR } from '@avatarsd-llc/libtracer-client';
14import { standInNode } from './stand-in-node.mjs';
15
16const client = new LibtracerClient(standInNode().loopback());
17
18// Nothing was ever written at /sensor/missing, so the node answers FWD{REPLY, kind=ERROR}.
19try {
20 await client.read('/sensor/missing');
21 assert.fail('a read of an absent vertex must reject');
22} catch (err) {
23 assert.ok(err instanceof FwdError);
24 assert.equal(err.code, FWD_ERROR.NOT_FOUND);
25 console.log(`read /sensor/missing -> ${err.codeName} (0x${err.code.toString(16).padStart(4, '0')})`);
26}
Run it from bindings/typescript/, after npm ci && npm run build:
$ node examples/remote-error.mjs
See also: protocol TLVs reference.