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 {
constructor(msg: string) {
super(msg);
constructor(msg: string, { row, col }: SourceLocation) {
super(`${msg} at line ${row + 1} char ${col + 1}`);
}
}

View File

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

View File

@ -8,7 +8,7 @@ const isCommentWithinInterval = (comment: Comment, interval: Interval): boolean
const validateCommentOffsets = (interval: Interval) => {
for (const comment of interval.comments) {
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);
}
}
};