Implementation:8beeeaaat Touchdesigner mcp Error Categorization
| Knowledge Sources | |
|---|---|
| Domains | Error_Handling, Error_Classification |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for classifying exceptions into six error categories and converting them into structured Result objects with decorator-based wrapping.
Description
The error_handling module provides the ErrorCategory enum (INTERNAL, VALIDATION, NOT_FOUND, PERMISSION, NETWORK, EXTERNAL), the categorize_error function that inspects exception type and message keywords, the format_error function that prefixes a message with its category, and the handle_service_errors decorator. The decorator wraps a service method in a try/except that categorizes the exception, logs it with traceback, and returns an error_result carrying the formatted message and an `errorCategory` metadata dict — so callers and the controller can map errors to HTTP status reasons without re-inspecting the exception.
Usage
Decorate api_service methods with @handle_service_errors to guarantee they return Result objects. Call categorize_error directly when classifying a raw exception outside the decorator.
Code Reference
Source Location
- Repository: 8beeeaaat_Touchdesigner_mcp
- File: td/modules/utils/error_handling.py
- Lines: 1-106
Signature
class ErrorCategory(Enum):
INTERNAL = "INTERNAL"
VALIDATION = "VALIDATION"
NOT_FOUND = "NOT_FOUND"
PERMISSION = "PERMISSION"
NETWORK = "NETWORK"
EXTERNAL = "EXTERNAL"
def categorize_error(exception: Exception) -> ErrorCategory: ...
def format_error(message: str, category: Optional[ErrorCategory] = None) -> str: ...
def handle_service_errors(func: Callable[..., Result]) -> Callable[..., Result]: ...
Import
from utils.error_handling import (
ErrorCategory, categorize_error, format_error, handle_service_errors,
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| exception | Exception | Yes | The exception to classify |
| message | str | Yes (format_error) | Error message text |
| category | ErrorCategory | No | Override (defaults to INTERNAL) |
Outputs
| Name | Type | Description |
|---|---|---|
| categorize_error | ErrorCategory | One of six categories |
| format_error | str | "CATEGORY: message" |
| handle_service_errors | Result | error_result(message, {"errorCategory": ...}) |
Usage Examples
Decorating a service method
from utils.error_handling import handle_service_errors
@handle_service_errors
def get_node_detail(self, node_path: str):
op = op(node_path) # May raise td.TDExploreError
return {"success": True, "data": ...}
# On error: returns {"success": False, "error": "NOT_FOUND: ...", ...}
Direct categorization
from utils.error_handling import categorize_error, ErrorCategory
cat = categorize_error(FileNotFoundError("missing.tox"))
assert cat == ErrorCategory.NOT_FOUND