Skip to content

Handle errors at the right level

Decide what the user or runner should do when an operation fails: report it, stop, or continue with other elements. Catch exceptions where you can make that decision, usually in the script entry point or application shell.

from multiconn_archicad import UnifiedApi
from multiconn_archicad.errors import ArchicadAPIError, RequestError
from multiconn_archicad.models.official.types import ElementType

try:
    api = UnifiedApi()
    walls = api.official.element_listing.get_elements_by_type(ElementType.WALL)
except RequestError as error:
    print(f"Could not communicate with Archicad: {error}")
except ArchicadAPIError as error:
    print(f"Archicad rejected the command: {error}")
else:
    print(f"Walls found: {len(walls)}")

Client construction belongs inside the try here because automatic port discovery can fail before the first command is sent.

Choose what to catch

Exception What failed
APIConnectionError Connection or endpoint discovery.
CommandTimeoutError The request took too long.
InvalidResponseFormatError The response was not in the expected transport format.
RequestError Parent for connection, timeout, and response-format errors.
StandardAPIError An official command returned an error.
TapirCommandError A Tapir command returned an error.
ArchicadAPIError Parent for official and Tapir command errors.
APIErrorBase Parent for request and command errors.
BatchOperationError A batch policy raised because individual results failed.
MulticonnArchicadError Parent for library errors, including project-management errors.

Unavailable commands have more specific exceptions: StandardCommandUnavailable and AddOnCommandUnavailable. Project workflows can raise ProjectAlreadyOpenError, ProjectNotFoundError, or NotFullyInitializedError.

Generated input and response validation can raise Pydantic ValidationError. It is not a subclass of MulticonnArchicadError. Invalid arguments can also raise ordinary Python exceptions such as ValueError.

Separate a failed request from failed items

Some requests return a mixture of values and per-element errors. Use batch results to retain and report those outcomes. A request returning normally does not mean every item succeeded.

Do not silently replace an exception with an empty list: users could mistake "could not read" for "no matching elements." For model-changing commands, check the result before retrying; part of the work may already have completed.