Skip to content

Exceptions

All exceptions inherit from CanardError.

from canard import (
    CanardError,
    APIError,
    AuthenticationError,
    RunNotFoundError,
    TaskNotFoundError,
    ConfigurationError,
    TimeoutError,
    ResultsNotReadyError,
)

CanardError

Base exception for all Canard SDK errors.

try:
    run = client.get_run("run_invalid")
except CanardError as e:
    print(f"Something went wrong: {e}")

APIError

API communication failed. Has a status_code attribute.

try:
    run = client.get_run("run_abc123")
except APIError as e:
    print(f"API error {e.status_code}: {e}")

AuthenticationError

Invalid or missing API key. Returned on HTTP 401.

try:
    client = Client(api_url="https://api.canard.cloud", api_key="bad_key")
    client.list_runs()
except AuthenticationError:
    print("Check your API key")

RunNotFoundError

Run slug not found. Returned on HTTP 404.


TaskNotFoundError

Task not found.


ConfigurationError

Invalid SDK configuration (e.g., no API key found anywhere).

# Raised when no API key in env, file, or parameter
client = Client(api_url="https://api.canard.cloud")
# → ConfigurationError: No API key found

TimeoutError

Operation exceeded timeout.

try:
    run.wait_for_completion(timeout=60)
except TimeoutError:
    print(f"Run still {run.status} after 60s")

ResultsNotReadyError

Results not available yet (run not complete).

try:
    run.download_results("./results")
except ResultsNotReadyError:
    print(f"Run is still {run.status}")