diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-06-25 18:10:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-06-25 18:22:35 +0900 |
| commit | ae35f799ef6530736260a349ff026670fc600ff7 (patch) | |
| tree | fd8942061121c6125a4bebfaed07eff9bdeac036 | |
| parent | b8ff78a1a631fe27d7a66a454805a116d96738d8 (diff) | |
| download | blog.nsfisis.dev-ae35f799ef6530736260a349ff026670fc600ff7.tar.gz blog.nsfisis.dev-ae35f799ef6530736260a349ff026670fc600ff7.tar.zst blog.nsfisis.dev-ae35f799ef6530736260a349ff026670fc600ff7.zip | |
feat(nuldoc): improve readability of error messages
| -rw-r--r-- | nuldoc-src/xml.ts | 12 |
1 files changed, 11 insertions, 1 deletions
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"); +} |
