Skip to content

Commit

Permalink
Issue 19: Better missing file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPacker committed Jun 20, 2022
1 parent 005c05e commit fa19f56
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions mdpre
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import calendar


mdpre_level = "0.6.4+"
mdpre_date = "19 June, 2022"
mdpre_date = "20 June, 2022"
banner = "mdpre Markdown Preprocessor v" + mdpre_level + " (" + mdpre_date + ")"

log = partial(print, file=sys.stderr) # | create log to stderr
Expand Down Expand Up @@ -731,8 +731,12 @@ def interpretLoops(input_file2, loopController):
# Not recursive so add include file name to stack
includeStack.append(include_name)

with open(include_name, "r") as f:
stopIt, include_lines = parse_include(f.readlines())
try:
with open(include_name, "r") as f:
stopIt, include_lines = parse_include(f.readlines())
except:
sys.stderr.write(f"File {include_name} missing. Terminating.\n")
exit()

for line2 in include_lines:
input_file2.append(line2)
Expand Down Expand Up @@ -813,8 +817,14 @@ def parse_include(input_file):
+ include_name
+ "-->"
)
with open(include_name, "r") as f:
stopIt, include_lines = parse_include(f.readlines())

try:
with open(include_name, "r") as f:
stopIt, include_lines = parse_include(f.readlines())
except:
sys.stderr.write(f"File {include_name} missing. Terminating.\n")
exit()

for line2 in include_lines:
input_file2.append(line2)
if wantVerbose is True:
Expand Down

0 comments on commit fa19f56

Please sign in to comment.