From 4ab0392f707b26767eebb6e7f00e55a474732d63 Mon Sep 17 00:00:00 2001 From: TFWol <9045213+TFWol@users.noreply.github.com> Date: Thu, 11 Jan 2024 06:34:33 -0800 Subject: [PATCH 1/2] Resolved crashing nodes caused by `FileNotFoundError` during directory traversal - Implemented a `try-except` block in the `recursive_search` function to handle `FileNotFoundError` gracefully. - When encountering a file or directory path that cannot be accessed (causing `FileNotFoundError`), the code now logs a warning and skips processing for that specific path instead of crashing the node (CheckpointLoaderSimple was usually the first to break). This allows the rest of the directory traversal to proceed without interruption. --- folder_paths.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/folder_paths.py b/folder_paths.py index 641e5f0b2..4abed783b 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -138,15 +138,20 @@ def recursive_search(directory, excluded_dir_names=None): excluded_dir_names = [] result = [] - dirs = {directory: os.path.getmtime(directory)} + dirs = {} for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True): subdirs[:] = [d for d in subdirs if d not in excluded_dir_names] for file_name in filenames: relative_path = os.path.relpath(os.path.join(dirpath, file_name), directory) result.append(relative_path) + for d in subdirs: path = os.path.join(dirpath, d) - dirs[path] = os.path.getmtime(path) + try: + dirs[path] = os.path.getmtime(path) + except FileNotFoundError: + print(f"Warning: Unable to access {path}. Skipping this path.") + continue return result, dirs def filter_files_extensions(files, extensions): From 1dab412c79eccdd055265475a0bd31ba97e2cf9c Mon Sep 17 00:00:00 2001 From: TFWol <9045213+TFWol@users.noreply.github.com> Date: Sun, 14 Jan 2024 15:06:33 -0800 Subject: [PATCH 2/2] Add error handling to initial fix to keep cache intact --- folder_paths.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/folder_paths.py b/folder_paths.py index 4abed783b..ef9b8ccfa 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -139,6 +139,13 @@ def recursive_search(directory, excluded_dir_names=None): result = [] dirs = {} + + # Attempt to add the initial directory to dirs with error handling + try: + dirs[directory] = os.path.getmtime(directory) + except FileNotFoundError: + print(f"Warning: Unable to access {directory}. Skipping this path.") + for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True): subdirs[:] = [d for d in subdirs if d not in excluded_dir_names] for file_name in filenames: