From b219e790a480d4fd8f363824a4b8d79774d324d0 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 22 Aug 2024 08:22:06 -0700 Subject: [PATCH] fix: Move FileNotFoundError handling up after file open and read --- testsr.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/testsr.py b/testsr.py index 0b998fdce..701d2374e 100755 --- a/testsr.py +++ b/testsr.py @@ -15,12 +15,15 @@ def process_markdown(filename): try: with open(filename, "r") as file: content = file.read() + except FileNotFoundError: + print(json.dumps({"error": f"File '{filename}' not found."}, indent=4)) + return - # Split the content into sections based on '####' headers - sections = re.split(r"(?=####\s)", content) + # Split the content into sections based on '####' headers + sections = re.split(r"(?=####\s)", content) - results = [] - for section in sections: + results = [] + for section in sections: if not section.strip(): # Ignore empty sections continue # Extract the header (if present)