> ## Documentation Index
> Fetch the complete documentation index at: https://docs.narada.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Handling

> Handle Narada SDK errors and exceptions

## Error Types

The Narada SDK raises specific exceptions for different error conditions. All errors inherit from `NaradaError`.

```python theme={null}
from narada import (
    NaradaError,
    NaradaTimeoutError,
    NaradaUnsupportedBrowserError,
    NaradaExtensionMissingError,
    NaradaExtensionUnauthenticatedError,
    NaradaInitializationError
)
```

## Error Handling Examples

Look at the following examples to see how to handle different errors.

<AccordionGroup>
  <Accordion title="NaradaTimeoutError">
    Raised when operations exceed timeout limits.

    ```python theme={null}
    from narada import NaradaTimeoutError

    try:
        response = await agent.run(
            prompt='find a specific element',
            timeout=30
        )
    except NaradaTimeoutError:
        print("Operation timed out. Try increasing timeout or simplifying the task.")
    ```
  </Accordion>

  <Accordion title="NaradaUnsupportedBrowserError">
    Raised when using an unsupported browser.

    ```python theme={null}
    from narada import BrowserEnvironment, NaradaUnsupportedBrowserError

    env = BrowserEnvironment()
    try:
        await env.start()
    except NaradaUnsupportedBrowserError:
        print("Please use Chrome browser. Other browsers are not supported.")
    finally:
        await env.close()
    ```
  </Accordion>

  <Accordion title="NaradaExtensionMissingError">
    Raised when the Chrome extension is not installed.

    ```python theme={null}
    from narada import BrowserEnvironment, NaradaExtensionMissingError

    env = BrowserEnvironment()
    try:
        await env.start()
    except NaradaExtensionMissingError:
        print("Narada extension not found. Please install it from the Chrome Web Store.")
    finally:
        await env.close()
    ```
  </Accordion>

  <Accordion title="NaradaExtensionUnauthenticatedError">
    Raised when the extension is not signed in.

    ```python theme={null}
    from narada import BrowserEnvironment, NaradaExtensionUnauthenticatedError

    env = BrowserEnvironment()
    try:
        await env.start()
    except NaradaExtensionUnauthenticatedError:
        print("Please sign in to your Narada account in the Chrome extension.")
    finally:
        await env.close()
    ```
  </Accordion>

  <Accordion title="NaradaInitializationError">
    Raised when SDK initialization fails.

    ```python theme={null}
    from narada import BrowserEnvironment, NaradaInitializationError

    env = BrowserEnvironment()
    try:
        await env.start()
    except NaradaInitializationError:
        print("Failed to initialize SDK. Check your API key and internet connection.")
    finally:
        await env.close()
    ```
  </Accordion>
</AccordionGroup>

## Retry Pattern

For transient errors, implement retry logic:

```python theme={null}
import asyncio
from narada import Agent, BrowserEnvironment, NaradaTimeoutError

async def retry_operation(agent, prompt, max_retries=3):
    for attempt in range(max_retries):
        try:
            return await agent.run(prompt=prompt)
        except NaradaTimeoutError:
            if attempt == max_retries - 1:
                raise
            await agent.reset_agent_state()
            await asyncio.sleep(2 ** attempt)  # Exponential backoff

async def main():
    env = BrowserEnvironment()
    agent = Agent(environment=env)

    try:
        response = await retry_operation(
            agent,
            'search for "python tutorial"'
        )
        print(response.text)
    finally:
        await env.close()

asyncio.run(main())
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Catch Specific Errors" icon="bullseye-arrow">
    Handle specific error types rather than generic exceptions
  </Card>

  <Card title="Implement Retries" icon="arrows-rotate">
    Use retry logic for timeout and initialization errors
  </Card>

  <Card title="Log Errors" icon="file">
    Log errors with context for debugging
  </Card>

  <Card title="Graceful Degradation" icon="shield-check">
    Design fallback behavior when automation fails
  </Card>
</CardGroup>

<Tip>
  Most errors are recoverable. Check the error message and implement appropriate retry or fallback logic.
</Tip>
