Skip to content

Commit 0554a8d

Browse files
committed
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 carpentries/styles#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: swcarpentry/r-novice-gapminder#696 (comment) I fully admit that this is a kludge.
1 parent a283c4b commit 0554a8d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bin/lesson_check.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,14 @@ def check_codeblock_classes(self):
392392

393393
for node in self.find_all(self.doc, {'type': 'codeblock'}):
394394
cls = self.get_val(node, 'attr', 'class')
395-
self.reporter.check(cls in KNOWN_CODEBLOCKS or cls.startswith('language-'),
395+
self.reporter.check(cls is not none and (cls in KNOWN_CODEBLOCKS or
396+
cls.startswith('language-')),
396397
(self.filename, self.get_loc(node)),
397398
'Unknown or missing code block type {0}',
398399
cls)
400+
if not cls is None:
401+
print("NOTE: The AST was malformed and needs to be investigated")
402+
print(self.filename, self.get_loc(node))
399403

400404
def check_defined_link_references(self):
401405
"""Check that defined links resolve in the file.

0 commit comments

Comments
 (0)