Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:8beeeaaat Touchdesigner mcp Error Categorization

From Leeroopedia
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

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

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment