Skip to content

Self-improving AI Employees for everyone

refactor(plugins): RuntimeError -> NodeUserError for user-correctable failures (Wave 11.I, W3)

trohitgf019c0ab45b8
diff --git a/server/nodes/document/embedding_generator.py b/server/nodes/document/embedding_generator.py
index a1b34df6..aacdf68d 100644
--- a/server/nodes/document/embedding_generator.py
+++ b/server/nodes/document/embedding_generator.py
@@ -7,7 +7,7 @@ from typing import List, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
class EmbeddingGeneratorParams(BaseModel):
@@ -83,7 +83,7 @@ class EmbeddingGeneratorNode(ActionNode):
try:
from langchain_huggingface import HuggingFaceEmbeddings
except ImportError:
- raise RuntimeError(
+ raise NodeUserError(
"HuggingFace embeddings unavailable. "
"pip install langchain-huggingface sentence-transformers",
)
@@ -95,7 +95,7 @@ class EmbeddingGeneratorNode(ActionNode):
from langchain_ollama import OllamaEmbeddings
embedder = OllamaEmbeddings(model=model)
else:
- raise RuntimeError(f"Unknown provider: {provider}")
+ raise NodeUserError(f"Unknown provider: {provider}")
embeddings = await asyncio.to_thread(embedder.embed_documents, texts)
dimensions = len(embeddings[0]) if embeddings else 0
diff --git a/server/nodes/document/http_scraper.py b/server/nodes/document/http_scraper.py
index 0c7ee561..84ecd5fa 100644
--- a/server/nodes/document/http_scraper.py
+++ b/server/nodes/document/http_scraper.py
@@ -15,7 +15,7 @@ from bs4 import BeautifulSoup
from pydantic import BaseModel, ConfigDict, Field
from core.logging import get_logger
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
logger = get_logger(__name__)
@@ -130,7 +130,7 @@ class HttpScraperNode(ActionNode):
async def scrape(self, ctx: NodeContext, params: HttpScraperParams) -> HttpScraperOutput:
url = params.url
if not url:
- raise RuntimeError("URL is required")
+ raise NodeUserError("URL is required")
iteration_mode = params.iteration_mode
link_selector = params.link_selector or 'a[href$=".pdf"]'
@@ -140,7 +140,7 @@ class HttpScraperNode(ActionNode):
urls_to_fetch = []
if iteration_mode == 'date':
if not params.start_date or not params.end_date:
- raise RuntimeError("start_date/end_date required for date mode")
+ raise NodeUserError("start_date/end_date required for date mode")
placeholder = params.date_placeholder or '{date}'
start = datetime.strptime(params.start_date, "%Y-%m-%d")
end = datetime.strptime(params.end_date, "%Y-%m-%d")
diff --git a/server/nodes/document/vector_store.py b/server/nodes/document/vector_store.py
index fbd2f301..47db7f57 100644
--- a/server/nodes/document/vector_store.py
+++ b/server/nodes/document/vector_store.py
@@ -13,7 +13,7 @@ from typing import Any, Dict, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
class VectorStoreParams(BaseModel):
@@ -70,7 +70,7 @@ async def _chroma_op(operation: str, params: Dict[str, Any], collection: str) ->
try:
import chromadb
except ImportError:
- raise RuntimeError("ChromaDB unavailable. pip install chromadb")
+ raise NodeUserError("ChromaDB unavailable. pip install chromadb")
persist_dir = params.get('persist_dir', './data/vectors')
client = chromadb.PersistentClient(path=persist_dir)
@@ -126,7 +126,7 @@ async def _qdrant_op(operation: str, params: Dict[str, Any], collection: str) ->
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, PointStruct, VectorParams
except ImportError:
- raise RuntimeError("Qdrant client unavailable. pip install qdrant-client")
+ raise NodeUserError("Qdrant client unavailable. pip install qdrant-client")
url = params.get('qdrant_url', 'http://localhost:6333')
client = QdrantClient(url=url)
@@ -188,7 +188,7 @@ async def _pinecone_op(operation: str, params: Dict[str, Any], collection: str)
api_key = params.get('pinecone_api_key', '')
if not api_key:
- raise RuntimeError("Pinecone API key required")
+ raise NodeUserError("Pinecone API key required")
pc = Pinecone(api_key=api_key)
index = pc.Index(collection)
@@ -271,7 +271,7 @@ class VectorStoreNode(ActionNode):
elif backend == 'pinecone':
result = await _pinecone_op(operation, p, collection)
else:
- raise RuntimeError(f"Unknown backend: {backend_raw}")
+ raise NodeUserError(f"Unknown backend: {backend_raw}")
result['backend'] = backend
result['collection_name'] = collection
diff --git a/server/nodes/location/gmaps_create.py b/server/nodes/location/gmaps_create.py
index 13303bd1..378b2de7 100644
--- a/server/nodes/location/gmaps_create.py
+++ b/server/nodes/location/gmaps_create.py
@@ -6,7 +6,7 @@ from typing import Any, Dict, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
from ._credentials import GoogleMapsCredential
@@ -69,4 +69,4 @@ class GmapsCreateNode(ActionNode):
)
if response.get("success"):
return response.get("result") or response
- raise RuntimeError(response.get("error") or "Map create failed")
+ raise NodeUserError(response.get("error") or "Map create failed")
diff --git a/server/nodes/location/gmaps_locations.py b/server/nodes/location/gmaps_locations.py
index 7308f134..1d078dd2 100644
--- a/server/nodes/location/gmaps_locations.py
+++ b/server/nodes/location/gmaps_locations.py
@@ -6,7 +6,7 @@ from typing import Any, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
from ._credentials import GoogleMapsCredential
@@ -80,4 +80,4 @@ class GmapsLocationsNode(ActionNode):
)
if response.get("success"):
return response.get("result") or response
- raise RuntimeError(response.get("error") or "Geocoding failed")
+ raise NodeUserError(response.get("error") or "Geocoding failed")
diff --git a/server/nodes/location/gmaps_nearby_places.py b/server/nodes/location/gmaps_nearby_places.py
index aab5ba6d..e6c93e01 100644
--- a/server/nodes/location/gmaps_nearby_places.py
+++ b/server/nodes/location/gmaps_nearby_places.py
@@ -6,7 +6,7 @@ from typing import Any, Optional
from pydantic import BaseModel, ConfigDict, Field
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
from ._credentials import GoogleMapsCredential
@@ -59,4 +59,4 @@ class GmapsNearbyPlacesNode(ActionNode):
)
if response.get("success"):
return response.get("result") or response
- raise RuntimeError(response.get("error") or "Nearby places failed")
+ raise NodeUserError(response.get("error") or "Nearby places failed")
diff --git a/server/nodes/proxy/proxy_config.py b/server/nodes/proxy/proxy_config.py
index 13e8198e..1b37ad48 100644
--- a/server/nodes/proxy/proxy_config.py
+++ b/server/nodes/proxy/proxy_config.py
@@ -15,7 +15,7 @@ import httpx
from pydantic import BaseModel, ConfigDict, Field
from core.logging import get_logger
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
logger = get_logger(__name__)
@@ -384,5 +384,5 @@ class ProxyConfigNode(ActionNode):
async def dispatch(self, ctx: NodeContext, params: ProxyConfigParams) -> Any:
result = await execute_proxy_config(params.model_dump())
if not result.get("success"):
- raise RuntimeError(result.get("error") or "Proxy config failed")
+ raise NodeUserError(result.get("error") or "Proxy config failed")
return result
diff --git a/server/nodes/proxy/proxy_request.py b/server/nodes/proxy/proxy_request.py
index a50d21b6..02b6d9d1 100644
--- a/server/nodes/proxy/proxy_request.py
+++ b/server/nodes/proxy/proxy_request.py
@@ -6,7 +6,7 @@ from typing import Any, Dict, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
class ProxyRequestParams(BaseModel):
@@ -78,7 +78,7 @@ class ProxyRequestNode(ActionNode):
log = get_logger(__name__)
svc = get_proxy_service()
if not svc or not svc.is_enabled():
- raise RuntimeError(
+ raise NodeUserError(
"Proxy service not initialized. Use proxy_config tool to add a "
"provider first.",
)
@@ -86,7 +86,7 @@ class ProxyRequestNode(ActionNode):
raw = params.model_dump()
proxy_url = await svc.get_proxy_url(params.url, raw)
if not proxy_url:
- raise RuntimeError("No proxy provider available")
+ raise NodeUserError("No proxy provider available")
max_retries = params.max_retries
failover = raw.get("proxy_failover", True)
@@ -132,7 +132,7 @@ class ProxyRequestNode(ActionNode):
response_data = response.text
if response.status_code >= 400:
- raise RuntimeError(f"HTTP {response.status_code}: {response_data!r}")
+ raise NodeUserError(f"HTTP {response.status_code}: {response_data!r}")
return {
"status": response.status_code,
"data": response_data,
diff --git a/server/nodes/scraper/apify_actor.py b/server/nodes/scraper/apify_actor.py
index d5d9eae2..1e36fb31 100644
--- a/server/nodes/scraper/apify_actor.py
+++ b/server/nodes/scraper/apify_actor.py
@@ -13,7 +13,7 @@ from typing import Any, Dict, List, Literal, Optional
from pydantic import BaseModel, ConfigDict, Field
from core.logging import get_logger
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
from ._credentials import ApifyCredential
@@ -256,7 +256,7 @@ class ApifyActorNode(ActionNode):
async def run(self, ctx: NodeContext, params: ApifyActorParams) -> ApifyActorOutput:
client = await _get_apify_client()
if not client:
- raise RuntimeError(
+ raise NodeUserError(
"Apify API token not configured. Please add your token in Credentials.",
)
@@ -264,7 +264,7 @@ class ApifyActorNode(ActionNode):
if actor_id == "custom":
actor_id = params.custom_actor_id
if not actor_id:
- raise RuntimeError("Actor ID is required")
+ raise NodeUserError("Actor ID is required")
actor_input = _build_actor_input(params.model_dump())
timeout_secs = params.timeout
@@ -282,18 +282,18 @@ class ApifyActorNode(ActionNode):
)
if run_info is None:
- raise RuntimeError("Actor run failed - no result returned")
+ raise NodeUserError("Actor run failed - no result returned")
status = run_info.get("status", "UNKNOWN")
run_id = run_info.get("id", "")
dataset_id = run_info.get("defaultDatasetId", "")
if status == "FAILED":
- raise RuntimeError(run_info.get("errorMessage", "Actor run failed"))
+ raise NodeUserError(run_info.get("errorMessage", "Actor run failed"))
if status == "TIMED-OUT":
- raise RuntimeError("Actor timed out. Try increasing the timeout.")
+ raise NodeUserError("Actor timed out. Try increasing the timeout.")
if status == "ABORTED":
- raise RuntimeError("Actor run was aborted")
+ raise NodeUserError("Actor run was aborted")
items: List[Dict[str, Any]] = []
if dataset_id:
diff --git a/server/nodes/scraper/crawlee_scraper.py b/server/nodes/scraper/crawlee_scraper.py
index 684b27b0..78c5a2a9 100644
--- a/server/nodes/scraper/crawlee_scraper.py
+++ b/server/nodes/scraper/crawlee_scraper.py
@@ -15,7 +15,7 @@ from urllib.parse import urljoin
from pydantic import BaseModel, ConfigDict, Field
from core.logging import get_logger
-from services.plugin import ActionNode, NodeContext, Operation, TaskQueue
+from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, TaskQueue
logger = get_logger(__name__)
@@ -296,7 +296,7 @@ class CrawleeScraperNode(ActionNode):
async def scrape(self, ctx: NodeContext, params: CrawleeScraperParams) -> CrawleeScraperOutput:
url = (params.url or "").strip()
if not url:
- raise RuntimeError("URL is required")
+ raise NodeUserError("URL is required")
crawler_type = params.crawler_type
mode = params.mode
@@ -326,16 +326,16 @@ class CrawleeScraperNode(ActionNode):
max_concurrency, timeout_secs,
)
else:
- raise RuntimeError(f"Unknown crawler type: {crawler_type}")
+ raise NodeUserError(f"Unknown crawler type: {crawler_type}")
except ImportError as e:
msg = str(e).lower()
if 'playwright' in msg:
- raise RuntimeError(
+ raise NodeUserError(
"Playwright not installed. Run: "
"pip install 'crawlee[playwright]' && playwright install chromium",
)
if 'crawlee' in msg:
- raise RuntimeError(
+ raise NodeUserError(
"Crawlee not installed. Run: pip install 'crawlee[beautifulsoup]'",
)
raise