From 3e5cffba0fb0bbbe2c62216463dcd295b7772311 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Wed, 27 Oct 2021 16:08:44 +0200 Subject: [PATCH] fix: throw better error when JS parse fails This should help debugging challenges with invalid syntax. --- curriculum/test/utils/extract-js-comments.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/curriculum/test/utils/extract-js-comments.js b/curriculum/test/utils/extract-js-comments.js index b0dd7a6738..75ee28f047 100644 --- a/curriculum/test/utils/extract-js-comments.js +++ b/curriculum/test/utils/extract-js-comments.js @@ -6,8 +6,14 @@ const parser = acorn.Parser; function extractComments(js) { let comments = []; const file = { data: {} }; - parser.parse(js, { onComment: comments, ecmaVersion: 2020 }); + try { + parser.parse(js, { onComment: comments, ecmaVersion: 2020 }); + } catch { + throw Error(`extract-js-comments could not parse the code below, this challenge have invalid syntax: +${js} +`); + } comments .map(({ value }) => value.trim()) .forEach(comment => commentToData(file, comment));