cocoindex-io/cocoindex · error · TypeError

LiveComponent classes cannot be used with use_mount(). Use m

Error message

LiveComponent classes cannot be used with use_mount(). Use mount() instead.

What it means

LiveComponent classes own their own lifecycle and must be mounted with mount(), which returns a handle you can await for readiness. use_mount() is for plain functions whose result value is returned directly; combining the two is not supported, so the API rejects it up front.

Source

Thrown at python/cocoindex/_internal/api.py:279

    if pos_args and isinstance(pos_args[0], ComponentSubpath):
        subpath = pos_args[0]
        processor_fn = pos_args[1]
        args = pos_args[2:]
    else:
        processor_fn = pos_args[0]
        args = pos_args[1:]
        name = _default_subpath_name(processor_fn)
        if name is None:
            raise TypeError(
                "use_mount() requires a ComponentSubpath when the function has no "
                "__name__. Provide an explicit subpath as the first argument."
            )
        subpath = ComponentSubpath(Symbol(name))

    check_not_in_process_live("coco.use_mount")

    if is_live_component_class(processor_fn):
        raise TypeError(
            "LiveComponent classes cannot be used with use_mount(). "
            "Use mount() instead."
        )

    parent_ctx = get_context_from_ctx()
    child_path = build_child_path(parent_ctx, subpath)
    # One explicit value travels through core: capture once, pass to both
    # the processor (ContextVar restore in the wrapper) and the engine call.
    deadline_context = _deadline_for_engine()

    processor = create_core_component_processor(
        processor_fn,
        parent_ctx._env,
        child_path,
        args,
        kwargs,
        deadline_context=deadline_context,
    )

View on GitHub (pinned to e84aa99b32)

Solutions

  1. Use coco.mount(SomeLiveComponentClass, *args) and await handle.ready() on the returned handle instead of use_mount()
  2. If you actually need a return value, convert the class to a plain @coco.fn async function

Example fix

// before
result = await coco.use_mount(MyLiveComponent, cfg)
// after
handle = await coco.mount(MyLiveComponent, cfg)
await handle.ready()
Defensive patterns

Strategy: type-guard

Validate before calling

from cocoindex._internal.api import is_live_component_class  # or public equivalent

if is_live_component_class(fn):
    handle = await coco.mount(fn, *args)
else:
    result = await coco.use_mount(fn, *args)

Type guard

def is_live_component(fn) -> bool:
    return isinstance(fn, type)  # LiveComponents are classes; plain fns are not

Try / catch

try:
    result = await coco.use_mount(fn, *args)
except TypeError as e:
    if "LiveComponent" in str(e):
        await (await coco.mount(fn, *args)).ready()

Prevention

When it happens

Trigger: Calling coco.use_mount(SomeLiveComponentClass, ...) where the first argument is a class recognized by is_live_component_class().

Common situations: Confusing the two mounting APIs after refactoring a component from a function to a LiveComponent class (or copying a use_mount call and swapping in a class).

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08). Data as JSON: /api/errors/c9f6e86f7c7f5e71. Report an issue: GitHub.