From 0554a8d099cbc999121e36d59f402ea90fa20269 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Thu, 11 Mar 2021 09:08:08 -0800 Subject: [PATCH 1/2] Add catch for None type code block in lesson_check There are times when the AST is malformed and does not emit a class for the code element. We do not want the parser to crash when this happens, but we also want to notify ourselves that the AST is malformed. This should not result in an error because as we saw in https://github.com/carpentries/styles/issues/543, the parser itself can cause these malformations when the lesson itself renders well. Even though we fixed the previous issue with an updated parser, problems still persist: https://github.com/swcarpentry/r-novice-gapminder/pull/696#issuecomment-796265728 I fully admit that this is a kludge. --- bin/lesson_check.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/lesson_check.py b/bin/lesson_check.py index 193f994f..4aa1eec9 100644 --- a/bin/lesson_check.py +++ b/bin/lesson_check.py @@ -392,10 +392,14 @@ def check_codeblock_classes(self): for node in self.find_all(self.doc, {'type': 'codeblock'}): cls = self.get_val(node, 'attr', 'class') - self.reporter.check(cls in KNOWN_CODEBLOCKS or cls.startswith('language-'), + self.reporter.check(cls is not none and (cls in KNOWN_CODEBLOCKS or + cls.startswith('language-')), (self.filename, self.get_loc(node)), 'Unknown or missing code block type {0}', cls) + if not cls is None: + print("NOTE: The AST was malformed and needs to be investigated") + print(self.filename, self.get_loc(node)) def check_defined_link_references(self): """Check that defined links resolve in the file. From cce6a66f4b0273f703730e9729592a2dcc45f645 Mon Sep 17 00:00:00 2001 From: "Zhian N. Kamvar" Date: Thu, 11 Mar 2021 09:32:54 -0800 Subject: [PATCH 2/2] fix syntax I've removed the print condition, because it will just result in an error no matter what (sigh) --- bin/lesson_check.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bin/lesson_check.py b/bin/lesson_check.py index 4aa1eec9..74d50549 100644 --- a/bin/lesson_check.py +++ b/bin/lesson_check.py @@ -392,14 +392,11 @@ def check_codeblock_classes(self): for node in self.find_all(self.doc, {'type': 'codeblock'}): cls = self.get_val(node, 'attr', 'class') - self.reporter.check(cls is not none and (cls in KNOWN_CODEBLOCKS or + self.reporter.check(cls is not None and (cls in KNOWN_CODEBLOCKS or cls.startswith('language-')), (self.filename, self.get_loc(node)), 'Unknown or missing code block type {0}', cls) - if not cls is None: - print("NOTE: The AST was malformed and needs to be investigated") - print(self.filename, self.get_loc(node)) def check_defined_link_references(self): """Check that defined links resolve in the file.