Skip to content

Commit

Permalink
Improved Error Handling
Browse files Browse the repository at this point in the history
Added try-except for error handling:

In both handleAllFlag and find_duplicates, I added a try-except block around the future.result() call.
If an exception occurs, it catches the error, logs a message with the file path, and continues processing other files.
  • Loading branch information
Ankush0286 committed Oct 3, 2024
1 parent 3c11cff commit 8ec8eff
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions twinTrim/flagController.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def handleAllFlag(directory,file_filter,pb_color,bar_color):

# Update progress bar as files are processed
for future in as_completed(futures):
try:
future.result() # Ensures exception handling for each future
except Exception as e:
click.echo(click.style(f"Error processing file {futures[future]}: {str(e)}", fg='red'))
progress_bar.update(1)

click.echo(click.style("All files scanned and duplicates handled.", fg='green'))
Expand Down Expand Up @@ -60,7 +64,11 @@ def process_file(file_path):
futures = {executor.submit(process_file, file_path): file_path for file_path in all_files}

for future in as_completed(futures):
progress_bar.update(1)
try:
future.result() # Ensures exception handling for each future
except Exception as e:
click.echo(click.style(f"Error processing file {futures[future]}: {str(e)}", fg='red'))
progress_bar.update(1)

duplicates = []
for _, metadata in normalStore.items():
Expand All @@ -70,5 +78,3 @@ def process_file(file_path):
duplicates.append((original_path, duplicate_path))

return duplicates


0 comments on commit 8ec8eff

Please sign in to comment.