Coverage for openhcs/core/memory/exceptions.py: 25.0%

8 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-14 05:57 +0000

1""" 

2Memory conversion exceptions for OpenHCS. 

3 

4This module defines exceptions for memory conversion operations, 

5enforcing Clause 65 (Fail Loudly) and Clause 88 (No Inferred Capabilities). 

6""" 

7 

8 

9 

10class MemoryConversionError(Exception): 

11 """ 

12 Exception raised when memory conversion fails. 

13  

14 This exception is raised when a memory conversion operation fails and 

15 CPU fallback is not explicitly authorized. 

16  

17 Attributes: 

18 source_type: The source memory type 

19 target_type: The target memory type 

20 method: The conversion method that was attempted 

21 reason: The reason for the failure 

22 """ 

23 

24 def __init__(self, source_type: str, target_type: str, method: str, reason: str): 

25 """ 

26 Initialize a MemoryConversionError. 

27  

28 Args: 

29 source_type: The source memory type 

30 target_type: The target memory type 

31 method: The conversion method that was attempted 

32 reason: The reason for the failure 

33 """ 

34 self.source_type = source_type 

35 self.target_type = target_type 

36 self.method = method 

37 self.reason = reason 

38 

39 message = ( 

40 f"Cannot convert from {source_type} to {target_type} using {method}. " 

41 f"Reason: {reason}. " 

42 f"No CPU fallback permitted unless explicitly authorized via allow_cpu_roundtrip=True." 

43 ) 

44 

45 super().__init__(message)