Use comment source location in validation error

This commit is contained in:
Rene Saarsoo 2020-11-21 21:04:58 +02:00
parent 2f7b11d4ac
commit ea00d550fe
3 changed files with 6 additions and 6 deletions

View File

@ -1,5 +1,7 @@
import { SourceLocation } from "./tokenizer";
export class ValidationError extends Error { export class ValidationError extends Error {
constructor(msg: string) { constructor(msg: string, { row, col }: SourceLocation) {
super(msg); super(`${msg} at line ${row + 1} char ${col + 1}`);
} }
} }

View File

@ -563,8 +563,6 @@ Interval: 2:00 90%
@ 0:00 Find your rythm. @ 0:00 Find your rythm.
@ 3:10 Try to settle in for the effort @ 3:10 Try to settle in for the effort
`), `),
).toThrowErrorMatchingInlineSnapshot( ).toThrowErrorMatchingInlineSnapshot(`"Comment offset is larger than interval length at line 5 char 5"`);
`"Comment \\"@ 190 Try to settle in for the effort\\" has offset outside of interval"`,
);
}); });
}); });

View File

@ -8,7 +8,7 @@ const isCommentWithinInterval = (comment: Comment, interval: Interval): boolean
const validateCommentOffsets = (interval: Interval) => { const validateCommentOffsets = (interval: Interval) => {
for (const comment of interval.comments) { for (const comment of interval.comments) {
if (!isCommentWithinInterval(comment, interval)) { if (!isCommentWithinInterval(comment, interval)) {
throw new ValidationError(`Comment "@ ${comment.offset.seconds} ${comment.text}" has offset outside of interval`); throw new ValidationError(`Comment offset is larger than interval length`, comment.loc);
} }
} }
}; };