From ae35f799ef6530736260a349ff026670fc600ff7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 25 Jun 2023 18:10:10 +0900 Subject: feat(nuldoc): improve readability of error messages --- nuldoc-src/xml.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'nuldoc-src') diff --git a/nuldoc-src/xml.ts b/nuldoc-src/xml.ts index 87c2b71..847b5e1 100644 --- a/nuldoc-src/xml.ts +++ b/nuldoc-src/xml.ts @@ -203,7 +203,9 @@ function expect(p: Parser, expected: string) { } if (actual !== expected) { throw new XmlParseError( - `[parse.expect] expected ${expected}, but actually got ${actual} (pos: ${p.index})`, + `[parse.expect] expected ${expected}, but actually got ${ + escapeForHuman(actual) + } (pos: ${p.index})`, ); } } @@ -257,3 +259,11 @@ function replaceEntityReferences(s: string): string { .replaceAll(/'/g, "'") .replaceAll(/"/g, '"'); } + +function escapeForHuman(s: string): string { + // support more characters? + return s + .replaceAll("\n", "\\n") + .replaceAll("\t", "\\t") + .replaceAll("\r", "\\r"); +} -- cgit v1.2.3-70-g09d2