mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
The next object runtime moves from the private repository into pi: src/next (contracts, hosts and objects, documents, derives, links and relays, routines and jobs, the store) with its tests and examples in test/next, src/next-node (Node compression), and its design in docs/next (design.md, the decision log decisions.md, the slice plan slices.md, slice specs, books and benchmarks). AGENTS.md gets its code style. Not exported: the API changes with every slice until it has an entry point.
35 lines
1.8 KiB
TypeScript
35 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { ChordError, PluginError } from "../../../src/next/data/index.ts";
|
|
import { errorFromWire, wireError } from "../../../src/next/link/internal.ts";
|
|
|
|
describe("errors on the wire", () => {
|
|
it("carry a ChordError as its JSON, without stack or cause", () => {
|
|
const error = new ChordError({ code: "invalid", reason: "args", message: "bad" }, { cause: new Error("x") });
|
|
const wire = wireError(error);
|
|
expect(wire).toEqual({ kind: "chord", error: { code: "invalid", reason: "args", message: "bad" } });
|
|
const back = errorFromWire(JSON.parse(JSON.stringify(wire)));
|
|
expect(back).toBeInstanceOf(ChordError);
|
|
expect(back).toMatchObject({ code: "invalid", reason: "args", message: "bad" });
|
|
});
|
|
|
|
it("carry a PluginError's code, message and details only; the consumer rethrows a PluginError", () => {
|
|
const error = new PluginError("quota", "too many notes", { limit: 3 });
|
|
const wire = wireError(error);
|
|
expect(wire).toEqual({ kind: "plugin", code: "quota", message: "too many notes", details: { limit: 3 } });
|
|
const back = errorFromWire(wire);
|
|
expect(back).toBeInstanceOf(PluginError);
|
|
expect(back).toMatchObject({ code: "quota", message: "too many notes", details: { limit: 3 } });
|
|
expect(wireError(new PluginError("c", "m"))).toEqual({ kind: "plugin", code: "c", message: "m" });
|
|
});
|
|
|
|
it("carry anything else as the plugin code internal with its message", () => {
|
|
expect(wireError(new TypeError("boom"))).toEqual({ kind: "plugin", code: "internal", message: "boom" });
|
|
expect(wireError("plain")).toEqual({ kind: "plugin", code: "internal", message: "plain" });
|
|
});
|
|
|
|
it("throw on a malformed ChordError envelope (a protocol error)", () => {
|
|
expect(() => errorFromWire({ kind: "chord", error: { code: "nope", message: "m" } })).toThrow(
|
|
"Invalid ChordError JSON",
|
|
);
|
|
});
|
|
});
|