Skip to content

Exceptions

Every failure is surfaced as a BusyBarError subclass, so callers can catch the domain error rather than transport-specific exceptions.

busylib.exceptions

BusyBarError

Bases: Exception

Base class for all BUSY Bar library exceptions.

Allows callers to handle library failures via a single except clause.

BusyBarAPIError

BusyBarAPIError(error: str, code: int | None = None, *, status_code: int | None = None, method: str | None = None, path: str | None = None, payload: Any | None = None, request_id: str | None = None, response_excerpt: str | None = None)

Bases: BusyBarError

Raised when the BUSY Bar API returns an error response.

Provides access to the response payload for diagnostics.

error instance-attribute

error = error

code instance-attribute

code = code

status_code instance-attribute

status_code = status_code

method instance-attribute

method = method

path instance-attribute

path = path

payload instance-attribute

payload = payload

request_id instance-attribute

request_id = request_id

response_excerpt instance-attribute

response_excerpt = response_excerpt

BusyBarRequestError

BusyBarRequestError(message: str, *, method: str | None = None, path: str | None = None, request_id: str | None = None, attempts: int | None = None, original: Exception | None = None)

Bases: BusyBarError

Raised when a request cannot be sent (network/timeout).

Used for transport-level failures before a response is received.

message instance-attribute

message = message

method instance-attribute

method = method

path instance-attribute

path = path

request_id instance-attribute

request_id = request_id

attempts instance-attribute

attempts = attempts

original instance-attribute

original = original

BusyBarAPIVersionError

BusyBarAPIVersionError(*, library_version: str, device_version: str, message: str)

Bases: BusyBarError

Raised when Busy Lib and device API versions are incompatible.

Indicates that either firmware or library must be updated.

library_version instance-attribute

library_version = library_version

device_version instance-attribute

device_version = device_version

BusyBarUsbError

BusyBarUsbError(message: str)

Bases: BusyBarError

Raised when USB device is not connected or USB operation fails.

Covers discovery, connection, and command execution issues.

BusyBarProtocolError

BusyBarProtocolError(message: str, *, method: str, path: str, request_id: str | None = None, response_excerpt: str | None = None)

Bases: BusyBarError

Raised when a successful HTTP response has an unexpected payload format.

Used for 2xx responses that cannot be interpreted as required by endpoint.

method instance-attribute

method = method

path instance-attribute

path = path

request_id instance-attribute

request_id = request_id

response_excerpt instance-attribute

response_excerpt = response_excerpt

BusyBarResponseValidationError

BusyBarResponseValidationError(*, model: str, details: str, original: Exception | None = None)

Bases: BusyBarError

Raised when a successful API response does not match expected schema.

Wraps pydantic validation errors to keep a stable domain error contract.

model instance-attribute

model = model

details instance-attribute

details = details

original instance-attribute

original = original

BusyBarConversionError

BusyBarConversionError(message: str, *, path: str, original: Exception | None = None)

Bases: BusyBarError

Raised when local file conversion fails before upload to the device.

Used by storage upload flows to report unsupported formats and failed conversion pipelines with a stable domain exception type.

path instance-attribute

path = path

original instance-attribute

original = original

BusyBarRemovedEndpointError

BusyBarRemovedEndpointError(*, path: str, method: str, replacement: str | None = None)

Bases: BusyBarError

Raised when a helper targets a device endpoint that no longer exists.

Distinct from BusyBarAPIVersionError: updating the firmware will not make the call work, because the endpoint was withdrawn rather than added later.

path instance-attribute

path = path

method instance-attribute

method = method

replacement instance-attribute

replacement = replacement

BusyBarWebSocketError

BusyBarWebSocketError(message: str, *, path: str, original: Exception | None = None)

Bases: BusyBarError

Raised when WebSocket connection or stream processing fails.

Wraps low-level websocket library exceptions into a domain error type.

path instance-attribute

path = path

original instance-attribute

original = original

is_retryable_delivery_error

is_retryable_delivery_error(error: BusyBarError) -> bool

Classify BUSY Bar delivery failures for caller retry decisions.

Treats request/transport failures and explicitly transient HTTP statuses as retryable. Other 4xx responses are caller or authorization problems and should not be retried as-is.

format_delivery_error

format_delivery_error(error: BusyBarError) -> str

Format BUSY Bar delivery failure into a compact diagnostic string.

Keeps enough HTTP context and response body excerpt for service logs without duplicating full response-formatting logic in each integration.