Skip to content

Commit

Permalink
Add catch for None type code block in lesson_check
Browse files Browse the repository at this point in the history
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#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.
  • Loading branch information
zkamvar committed Mar 11, 2021
1 parent a283c4b commit 0554a8d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/lesson_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0554a8d

Please sign in to comment.