+doc fails fast when includecode has no content

This commit is contained in:
Konrad Malawski 2015-10-08 11:00:01 +02:00
parent 0756a2ff68
commit 608ca9d67e
4 changed files with 8 additions and 3 deletions

View file

@ -109,6 +109,12 @@ class IncludeCode(Directive):
return count
nonempty = filter(lambda l: l.strip(), lines)
if not nonempty:
return [document.reporter.error(
"Snippet ({}#{}) not found!".format(filename, section),
line=self.lineno
)]
tabcounts = map(lambda l: countwhile(lambda c: c == ' ', l), nonempty)
tabshift = min(tabcounts) if tabcounts else 0

View file

@ -98,6 +98,7 @@ class IncludeCode2(Directive):
text = ''.join(res)
if text == "":
# in includecode2 it indeed is a warning, an empty code block will be inserted
return [document.reporter.warning('Snippet "' + snippet + '" not found!', line=self.lineno)]
retnode = nodes.literal_block(text, text, source=fn)