From ff95d278ec64c78d1b61b7b14758c90e751af370 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 3 Jul 2026 17:44:56 +0200 Subject: [PATCH] ... --- src/aarecommon/errors/exception_handler.py | 30 ++++++++-------------- src/aarecommon/types.py | 10 ++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 src/aarecommon/types.py diff --git a/src/aarecommon/errors/exception_handler.py b/src/aarecommon/errors/exception_handler.py index 530ff84..b3fbf9b 100644 --- a/src/aarecommon/errors/exception_handler.py +++ b/src/aarecommon/errors/exception_handler.py @@ -12,15 +12,23 @@ logger = setup_logger("aareDAQ") class AareException(Exception): """Root of the aare exception hierarchy.""" - def __init__(self, message: str, *args, critical: bool = False, **kwargs): - super().__init__(message, *args, **kwargs) - self.message=message + def __init__(self, *args, critical: bool = False, **kwargs): + super().__init__( *args, **kwargs) self.critical = critical class AutomationError(AareException): """Errors that happen during a DAQ operation; route through automation flows.""" + _DEFAULT_MSG: str = "Generic Automation Error" + + def __init__(self, message: str | None = None, critical: bool = False, **kwargs): + self.message = message or self.__class__._DEFAULT_MSG + super().__init__(self.message, **kwargs) + self.critical = critical + + def __str__(self) -> str: + return self.message class AareUserError(AareException): """Bad input / mode misuse; routes through the input-correction flow.""" @@ -74,19 +82,11 @@ class TransformationInvalidException(AutomationError): ): super().__init__(message, critical=critical) - def __str__(self) -> str: - return self.message - - class StateTransitionFailed(BeamlineStateException): def __init__( self, message: str = "Beamline state transition failed", *, critical: bool=True ): super().__init__(message, critical=critical) - self.message = message - - def __str__(self) -> str: - return self.message class MaintenanceStateException(BeamlineStateException): @@ -95,19 +95,11 @@ class MaintenanceStateException(BeamlineStateException): ): super().__init__(message, critical=critical) - def __str__(self) -> str: - return self.message - - class DataCollectionException(AutomationError): """Group parent for data-collection-time exceptions; also raisable directly.""" - def __init__(self, message: str = "Data collection failed", *, critical: bool | None = None): super().__init__(message, critical=critical) - self.message = message - def __str__(self) -> str: - return self.message class RasterScanException(DataCollectionException): diff --git a/src/aarecommon/types.py b/src/aarecommon/types.py new file mode 100644 index 0000000..f43fef6 --- /dev/null +++ b/src/aarecommon/types.py @@ -0,0 +1,10 @@ +from typing import Annotated, TypeAliasType +from pydantic import WithJsonSchema + +Jsonable = TypeAliasType( + "Jsonable", int | float | str | bool | None | list["Jsonable"] | dict[str, "Jsonable"] +) + +JsonableDict = TypeAliasType( + "JsonableDict", Annotated[dict[str, Jsonable], WithJsonSchema({"type": "object"})] +)