From 77a1cf4c890e887bb76a6d324dc606523892bd01 Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Mon, 6 Jul 2026 00:23:57 +0000 Subject: [PATCH] fix(NamedGraphError): report the offending graph IRI in the message The error message interpolated quad.value, which is always the empty string for an RDF/JS Quad, so the message never named the graph that caused the failure. Use quad.graph.value instead, and add a regression test asserting the thrown message contains the offending graph IRI. Co-Authored-By: Claude Fable 5 --- src/errors/NamedGraphError.ts | 2 +- test/unit/named_graph.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/errors/NamedGraphError.ts b/src/errors/NamedGraphError.ts index be55707..e596884 100644 --- a/src/errors/NamedGraphError.ts +++ b/src/errors/NamedGraphError.ts @@ -8,6 +8,6 @@ import type { Quad } from "@rdfjs/types" */ export class NamedGraphError extends QuadError { constructor(quad: Quad, cause?: any) { - super(quad, `Graph must be default (empty) but was ${quad.value}`, cause) + super(quad, `Graph must be default (empty) but was ${quad.graph.value}`, cause) } } diff --git a/test/unit/named_graph.test.ts b/test/unit/named_graph.test.ts index 86c8a6e..61286ae 100644 --- a/test/unit/named_graph.test.ts +++ b/test/unit/named_graph.test.ts @@ -117,6 +117,16 @@ await describe("namedGraph", async () => { ) }) + await it("NamedGraphError message reports the offending graph IRI", () => { + const ds = new SomeDataset(storeWithNamedGraph(), DataFactory).namedGraph + const offendingGraph = DataFactory.namedNode("https://other.org/g") + + assert.throws( + () => ds.add(DataFactory.quad(s, p, o, offendingGraph)), + (error: unknown) => error instanceof NamedGraphError && error.message.includes(offendingGraph.value), + ) + }) + await it("throws TermTypeError when matching with a non-default graph", () => { const ds = new SomeDataset(storeWithNamedGraph(), DataFactory).namedGraph