/ src / solace_agent_mesh / common / exceptions.py
exceptions.py
 1  """Custom exceptions for Solace Agent Mesh."""
 2  
 3  
 4  class MessageSizeExceededError(Exception):
 5      """Raised when a message exceeds the maximum allowed size."""
 6  
 7      def __init__(self, actual_size: int, max_size: int, message: str = None):
 8          """Initialize the MessageSizeExceededError.
 9  
10          Args:
11              actual_size: The actual size of the message in bytes.
12              max_size: The maximum allowed size in bytes.
13              message: Optional custom error message. If None, a default message
14                      will be generated.
15          """
16          self.actual_size = actual_size
17          self.max_size = max_size
18  
19          if message is None:
20              message = (
21                  f"Message size {actual_size} bytes exceeds maximum limit of "
22                  f"{max_size} bytes"
23              )
24  
25          super().__init__(message)
26  
27  
28  class ComponentInitializationError(Exception):
29      """Raised when a SAM component fails to initialize."""
30  
31      def __init__(self, component_identifier: str, original_error: Exception, message: str = None):
32          """Initialize the ComponentInitializationError.
33  
34          Args:
35              component_identifier: The identifier of the component that failed to initialize.
36              original_error: The original exception that caused the failure.
37              message: Optional custom error message. If None, a default message
38                      will be generated.
39          """
40          self.component_identifier = component_identifier
41          self.original_error = original_error
42  
43          if message is None:
44              message = (
45                  f"Component {component_identifier} failed to initialize: "
46                  f"{original_error}"
47              )
48  
49          super().__init__(message)