Handit.AI
  • Introduction
    • Introduction
    • Quick Start
  • Agent Creation
    • Overview
    • Interactive Agent Setup
    • Define Your Agent with a JSON Configuration
  • Code Integration
    • Overview
    • MCP Server Setup
    • Context Based Setup
    • Manual Setup
  • Best Practices
    • Input/Output Tracking
    • Service Initialization
    • Error Handling
Powered by GitBook
On this page
  • Error Propagation
  • Examples
  • Node.js
  • Python
  • Best Practices
  • Common Pitfalls
  1. Best Practices

Error Handling

This guide explains how to properly handle errors in your Handit.AI implementation.

Error Propagation

Handit.AI will propagate any errors thrown in your functions through the tracing system. This means:

  1. If your function throws an error, it will be:

    • Captured by the tracing system

    • Included in the trace data

    • Propagated to the caller

  2. You don't need to try/catch around Handit.AI functions:

    • The wrappers handle error propagation

    • Errors will be properly traced

    • No need for additional error handling

Examples

Node.js

// Correct: Let errors propagate
const tracedProcessor = traceAgentNode({
  agentNodeId: "data-processor",
  callback: async (input) => {
    // If this throws, the error will be properly traced
    const result = await processData(input);
    return result;
  }
});

// Incorrect: Don't wrap Handit.AI functions in try/catch
const wrongProcessor = traceAgentNode({
  agentNodeId: "data-processor",
  callback: async (input) => {
    try {
      // Don't do this - Handit.AI handles errors
      const result = await processData(input);
      return result;
    } catch (error) {
      // Don't catch Handit.AI errors
      console.error(error);
      throw error;
    }
  }
});

Python

# Correct: Let errors propagate
traced_processor = trace_agent_node(
    agent_node_id="data-processor",
    callback=async (input_data):
        # If this raises, the error will be properly traced
        result = await process_data(input_data)
        return result
)

# Incorrect: Don't wrap Handit.AI functions in try/except
wrong_processor = trace_agent_node(
    agent_node_id="data-processor",
    callback=async (input_data):
        try:
            # Don't do this - Handit.AI handles errors
            result = await process_data(input_data)
            return result
        except Exception as e:
            # Don't catch Handit.AI errors
            print(f"Error: {e}")
            raise
)

Best Practices

  1. Error Handling

    • Let errors propagate naturally

    • Don't catch Handit.AI errors

    • Focus on handling your application's errors

  2. Error Logging

    • Log errors at the appropriate level

    • Include relevant context

    • Don't duplicate error handling

  3. Error Recovery

    • Implement recovery logic in your application

    • Handle retries if needed

    • Maintain application state

Common Pitfalls

  1. Over-catching Errors

    • Don't catch errors unnecessarily

    • Let Handit.AI handle its own errors

    • Focus on your application's error handling

  2. Error Transformation

    • Don't transform Handit.AI errors

    • Preserve error context

    • Let errors propagate naturally

  3. Silent Failures

    • Don't silently catch errors

    • Ensure errors are properly logged

    • Maintain error visibility

PreviousService Initialization

Last updated 1 month ago