Show errors and API output URLs to the user (change log levels) (#131)

This commit is contained in:
Christian Byrne 2025-05-05 01:22:49 -07:00 committed by GitHub
parent 337e707103
commit d010dd9d80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 33 deletions

View File

@ -1,11 +1,3 @@
import logging
import time
from typing import Callable
import io
from comfy.cli_args import args
from comfy import utils
"""
API Client Framework for api.comfy.org.
@ -97,21 +89,18 @@ operation = PollingOperation(
result = operation.execute(client=api_client) # Returns the final ImageGenerationResult when done
"""
from typing import (
Dict,
Type,
Optional,
Any,
TypeVar,
Generic,
)
from pydantic import BaseModel, Field
import logging
import time
import io
from typing import Dict, Type, Optional, Any, TypeVar, Generic, Callable
from enum import Enum
import json
import requests
from urllib.parse import urljoin
from pydantic import BaseModel, Field
# Import models from your generated stubs
from comfy.cli_args import args
from comfy import utils
T = TypeVar("T", bound=BaseModel)
R = TypeVar("R", bound=BaseModel)
@ -475,7 +464,7 @@ class SynchronousOperation(Generic[T, R]):
return self._parse_response(resp)
except Exception as e:
logging.debug(f"[DEBUG] API Exception: {str(e)}")
logging.error(f"[DEBUG] API Exception: {str(e)}")
raise Exception(str(e))
def _parse_response(self, resp):
@ -554,7 +543,7 @@ class PollingOperation(Generic[T, R]):
return TaskStatus.FAILED
return TaskStatus.PENDING
except Exception as e:
logging.debug(f"Error extracting status: {e}")
logging.error(f"Error extracting status: {e}")
return TaskStatus.PENDING
def _poll_until_complete(self, client: ApiClient) -> R:
@ -609,8 +598,9 @@ class PollingOperation(Generic[T, R]):
progress.update(100)
return self.final_response
elif status == TaskStatus.FAILED:
logging.debug(f"[DEBUG] Task failed: {json.dumps(resp)}")
raise Exception(f"Task failed: {json.dumps(resp)}")
message = f"Task failed: {json.dumps(resp)}"
logging.error(f"[DEBUG] {message}")
raise Exception(message)
else:
logging.debug("[DEBUG] Task still pending, continuing to poll...")
@ -621,5 +611,5 @@ class PollingOperation(Generic[T, R]):
time.sleep(self.poll_interval)
except Exception as e:
logging.debug(f"[DEBUG] Polling error: {str(e)}")
logging.error(f"[DEBUG] Polling error: {str(e)}")
raise Exception(f"Error while polling: {str(e)}")

View File

@ -179,7 +179,7 @@ def validate_prompts(prompt: str, negative_prompt: str, max_length: int) -> bool
return True
def validate_task_creation_response(response):
def validate_task_creation_response(response) -> None:
"""Validates that the Kling task creation request was successful."""
if not is_valid_task_creation_response(response):
error_msg = f"Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}"
@ -187,7 +187,7 @@ def validate_task_creation_response(response):
raise KlingApiError(error_msg)
def validate_video_result_response(response):
def validate_video_result_response(response) -> None:
"""Validates that the Kling task result contains a video."""
if not is_valid_video_response(response):
error_msg = f"Kling task {response.data.task_id} succeeded but no video data found in response."
@ -195,7 +195,7 @@ def validate_video_result_response(response):
raise KlingApiError(error_msg)
def validate_image_result_response(response):
def validate_image_result_response(response) -> None:
"""Validates that the Kling task result contains an image."""
if not is_valid_image_response(response):
error_msg = f"Kling task {response.data.task_id} succeeded but no image data found in response."
@ -221,7 +221,7 @@ def get_camera_control_input_config(
def get_video_from_response(response) -> KlingVideoResult:
"""Returns the first video object from the Kling video generation task result."""
video = response.data.task_result.videos[0]
logging.debug(
logging.info(
"Kling task %s succeeded. Video URL: %s", response.data.task_id, video.url
)
return video
@ -229,7 +229,7 @@ def get_video_from_response(response) -> KlingVideoResult:
def get_images_from_response(response) -> list[KlingImageResult]:
images = response.data.task_result.images
logging.debug("Kling task %s succeeded. Images: %s", response.data.task_id, images)
logging.info("Kling task %s succeeded. Images: %s", response.data.task_id, images)
return images
@ -255,10 +255,7 @@ def image_result_to_node_output(
class KlingNodeBase(ComfyNodeABC):
"""
Base class for Kling nodes.
"""
"""Base class for Kling nodes."""
FUNCTION = "api_call"
CATEGORY = "api node/video/Kling"

View File

@ -173,7 +173,7 @@ class PikaNodeBase(ComfyNodeABC):
raise PikaApiError(error_msg)
video_url = str(final_response.url)
logging.debug("Pika task %s succeeded. Video URL: %s", task_id, video_url)
logging.info("Pika task %s succeeded. Video URL: %s", task_id, video_url)
return (download_url_to_video_output(video_url),)