diff --git a/cli/lib/validation.ts b/cli/lib/validation.ts index e34fb5673..b08c11b9f 100644 --- a/cli/lib/validation.ts +++ b/cli/lib/validation.ts @@ -1,11 +1,11 @@ -import type { NamedNode, Quad } from '@rdfjs/types' +import type { Literal, NamedNode, Quad } from '@rdfjs/types' import { turtle } from '@tpluscode/rdf-string' import type { Context } from 'barnard59-core/lib/Pipeline' import { validateQuad } from 'rdf-validate-datatype' export function validate(this: Context, quad: Quad): Quad { if (!validateQuad(quad)) { - throw new Error(`Quad object has invalid datatype:\n\t${quadToString(quad)}`) + throw new Error(`${errorMessage(quad)}\n\n${quadToString(quad)}`) } return quad @@ -17,3 +17,12 @@ function quadToString(quad: Quad): string { graph: quad.graph as NamedNode, }) } + +function errorMessage(quad: Quad): string { + const literal = quad.object as Literal + if (!literal.datatype) { + return `Invalid datatype for non-literal ${literal.value}` + } + + return `literal "${literal.value}" is not a valid value for datatype <${literal.datatype.value}>.` +}