| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- """Typed exceptions for the hth Python SDK."""
- from __future__ import annotations
- from typing import Any
- class HthError(Exception):
- """Base class for all SDK errors."""
- class StubsNotGenerated(HthError):
- """Python protobuf stubs are missing; run tools/gen_python_stubs.py."""
- class TransportError(HthError):
- """Unix-socket / gRPC transport failure."""
- class ApiVersionMismatch(HthError):
- def __init__(self, found: str, expected: str) -> None:
- self.found = found
- self.expected = expected
- super().__init__(
- f"API version mismatch: daemon reported {found!r}, SDK expects {expected!r}"
- )
- class LeaseError(HthError):
- """Control lease rejected, missing, mismatched, or expired."""
- class LeaseExpired(LeaseError):
- pass
- class LeaseMismatch(LeaseError):
- pass
- class ActionRejected(HthError):
- def __init__(self, reason: str, message: str = "", command_id: str = "") -> None:
- self.reason = reason
- self.message = message
- self.command_id = command_id
- super().__init__(f"action rejected ({reason}): {message}".strip())
- class ConfirmationNotProven(HthError):
- """Raised only if a caller treats SET_ALL as CONFIRMED.
- Current Prod2U UART has no ACK. A successful serial write is UNCONFIRMED.
- """
- class DeviceEpochChanged(HthError):
- """Device epoch advanced (reconnect, daemon restart, profile change).
- Previous snapshots, leases, and in-flight outcomes are not truth for the
- new epoch. Callers must re-read capabilities/snapshot and re-acquire a lease.
- """
- def __init__(self, old_epoch: int, new_epoch: int, device_id: str = "") -> None:
- self.old_epoch = old_epoch
- self.new_epoch = new_epoch
- self.device_id = device_id
- super().__init__(
- f"device_epoch changed {old_epoch} -> {new_epoch} device={device_id!r}"
- )
- class DataGap(HthError):
- """Telemetry stream dropped snapshots; sequence is no longer contiguous."""
- def __init__(self, dropped_count: int = 0, resume_after_event_id: int = 0, **extra: Any) -> None:
- self.dropped_count = dropped_count
- self.resume_after_event_id = resume_after_event_id
- self.extra = extra
- super().__init__(
- f"telemetry data gap dropped={dropped_count} resume_after_event_id={resume_after_event_id}"
- )
- class NotConnected(HthError):
- """The requested role (observe/control) has no channel."""
|