From 7b20711720e77c22a2a80cdc5e3e55566176707b Mon Sep 17 00:00:00 2001 From: Ian Andwati Date: Fri, 16 Jun 2023 08:28:14 +0300 Subject: [PATCH] fix: added try catch block to handle invalid images --- .gitignore | 6 +++++- cli.py | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c514c5d..f2c4413 100644 --- a/.gitignore +++ b/.gitignore @@ -168,4 +168,8 @@ poetry.toml .ruff_cache/ # LSP config files -pyrightconfig.json \ No newline at end of file +pyrightconfig.json + +rejects/ +done/ +.vscode/ \ No newline at end of file diff --git a/cli.py b/cli.py index 9bc4e67..18af5cf 100644 --- a/cli.py +++ b/cli.py @@ -1,5 +1,6 @@ import argparse from pathlib import Path +import cv2 from sorter.image_sorter import process_image # CLI argument parsing @@ -28,7 +29,13 @@ def main(): # Process the images for image_path in image_paths: - process_image(image_path, pass_folder, reject_folder) + """ + try catch block to handle errors in processing individual images. + """ + try: + process_image(image_path, pass_folder, reject_folder) + except cv2.error as e: + print(f"Error processing image {image_path.name}: {str(e)}") print("Sorting complete.")