Skip to content

Commit b975273

Browse files
committed
Add slightly better error messages
1 parent 12319c6 commit b975273

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ class JsonParser<T> {
5959
return str;
6060
}
6161

62-
async #nextNonEof(len?: number): Promise<string> {
62+
async #nextNonEof(len?: number, message?: string): Promise<string> {
6363
const chunk = await this.#next(len);
64-
assert(chunk !== undefined, 'Unexpected end of JSON input.');
64+
assert(chunk !== undefined, `Unexpected end of JSON input: ${message}`);
6565
return chunk!;
6666
}
6767

6868
async #skipWhiteSpaces(): Promise<string> {
6969
for (
70-
let char = await this.#nextNonEof();
70+
let char = await this.#nextNonEof(1, 'skipWhiteSpaces');
7171
;
72-
char = await this.#nextNonEof()
72+
char = await this.#nextNonEof(1, 'skipWhiteSpaces')
7373
) {
7474
if (!this.#isWhitespace(char)) return char;
7575
}
7676
}
7777

7878
async #expectNext(expected: string): Promise<string> {
79-
const char = await this.#nextNonEof(expected.length);
80-
assertEq(char, expected, `Expected '${expected}' got '${char} '`);
79+
const char = await this.#nextNonEof(expected.length, `Expected '${expected}', got EOF.`);
80+
assertEq(char, expected, `Expected '${expected}' got '${char}'`);
8181
return char;
8282
}
8383

0 commit comments

Comments
 (0)