From d9589a989c4b0b22d8ffefb7f248220715c02a53 Mon Sep 17 00:00:00 2001 From: limbicnation Date: Sat, 3 May 2025 19:45:55 +0200 Subject: [PATCH] Update with Better Error Handling --- __init__.py | 59 ++++++++++++++++++++++++++++-------------------- requirements.txt | 3 +++ 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/__init__.py b/__init__.py index 465d939..26238c1 100644 --- a/__init__.py +++ b/__init__.py @@ -50,7 +50,7 @@ for module_name, min_version in required_dependencies.items(): logger.warning(f"Missing required dependency: {module_name}>={min_version}") if missing_dependencies: - # Create a placeholder node that displays an error message + # Create placeholder node with dependency error class DependencyErrorNode: """Placeholder node that shows dependency installation instructions.""" @@ -76,38 +76,47 @@ if missing_dependencies: NODE_DISPLAY_NAME_MAPPINGS = { "DepthEstimationNode": "Depth Estimation (Missing Dependencies)" } - - logger.error(f"DepthEstimation Node disabled due to missing dependencies: {', '.join(missing_dependencies)}") - logger.error(f"Please install with: pip install {' '.join(missing_dependencies)}") else: - # All dependencies are available, import the actual node + # All dependencies are available, try to import the actual node try: - # Import the current implementation from .depth_estimation_node import DepthEstimationNode - logger.info("Successfully loaded depth estimation node") - except ImportError as e: - logger.error(f"Failed to import node implementation: {e}") - # Create minimal placeholder if the import fails - class DepthEstimationNode: + # Register the actual depth estimation node + NODE_CLASS_MAPPINGS = { + "DepthEstimationNode": DepthEstimationNode + } + + NODE_DISPLAY_NAME_MAPPINGS = { + "DepthEstimationNode": "Depth Estimation" + } + except Exception as e: + # Capture any import errors that might occur with transformers + logger.error(f"Error importing depth estimation node: {str(e)}") + + # Create a more specific error node + class TransformersErrorNode: @classmethod def INPUT_TYPES(cls): - return {"required": {"image": ("IMAGE",)}} - RETURN_TYPES = ("IMAGE",) - FUNCTION = "estimate_depth" + return {"required": {}} + + RETURN_TYPES = ("STRING",) + FUNCTION = "error_message" CATEGORY = "depth" - def estimate_depth(self, image): - return (image,) # Just pass through the image - - # Register the actual depth estimation node - NODE_CLASS_MAPPINGS = { - "DepthEstimationNode": DepthEstimationNode - } - - NODE_DISPLAY_NAME_MAPPINGS = { - "DepthEstimationNode": "Depth Estimation" - } + def error_message(self): + if "Descriptors cannot be created directly" in str(e): + message = "Protobuf version conflict. Run: pip install protobuf==3.20.3" + else: + message = f"Error loading depth estimation: {str(e)}" + return (message,) + + NODE_CLASS_MAPPINGS = { + "DepthEstimationNode": TransformersErrorNode + } + + NODE_DISPLAY_NAME_MAPPINGS = { + "DepthEstimationNode": "Depth Estimation (Error)" + } # Module exports __all__ = [ diff --git a/requirements.txt b/requirements.txt index e521a67..576a9bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,9 @@ # requirements.txt for ComfyUI-DepthEstimation Node # Note: These are minimum requirements. ComfyUI's environment may provide newer versions. +# Fix for protobuf errors +protobuf==3.20.3 + # Core dependencies tokenizers>=0.13.3 # Pre-built version compatible with most platforms transformers>=4.20.0 # Required for Depth Anything models, but ComfyUI may have a specific version